In my software, I'm using a PF_UNIX-socket for IPC.
Until now I need to allocate a (pre-)buffer via malloc
to prepare the data before writing it via write
into the buffer.
Now I was wondering:
The socket-fd already has a buffer of eg. 64kb, so why can't I simply directly prepare & write my data into that buffer like in this way:
// stupid example-code, don't copy
void *fd_buffer = get_buffer_of_fd(fd)
fd_buffer[0] = 1
fd_buffer[1] = 2
fd_buffer[2] = 3
memcpy(fd_buffer, 5, 5)
...
commit_buffer_of_fd(fd, xbytes); // xBytes is DYNAMIC and not known until this point!!
If this would be possible, I could save the roundtrip of copying into the pre-buffer, writing into the socket from the pre-buffer and even allocate the pre-buffer.
Has anyone an idea if that is possible?