(How) Can I determine the socket family from the socket file descriptor

前端 未结 3 906
忘了有多久
忘了有多久 2021-01-02 20:02

I am writing an API which includes IPC functions which send data to another process which may be local or on another host. I\'d really like the send function to be as simpl

3条回答
  •  遥遥无期
    2021-01-02 20:53

    If you control the client and server code I have a different suggestion, which I've used successfully in the past.

    Have the first four bytes of your message be a known integer value. The receiver can then inspect the first four bytes to see if it matches the known value. If it matches, then no byte swapping is needed.

    This saves you from having to do byte swapping when both machines have the same endianness.

提交回复
热议问题