This uses SOCK_STREAM, so you will not get the separated out messages you expect, instead you will read the messages back sometimes partially and sometimes several of them combined. This further interacts with fd passing in that you can't expect to recieve the sent fd with the "same" message as you sent them with.

Going to SOCK_DGRAM is perhaps a better way.