I have non-blocking socket (TCP or UPD socket) with using kqueue/epoll (FreeBSD/Linux). When I want to transmit bytes to other side I can use write/send/sendto. Each of them take char* buffer to transmit, but I don`t understand when I have to free memory of buffer after calling write/send/sendto.
- Is it correct that if write/send/sendto return the number of bytes accepted and this number equals buffer size, I can free memory of buffer immediately? Or I have to wait EVFILT_WRITE (kqueue) or EPOLLOUT (Linux) events to free memory of buffer?
- Is it correct that if write/send/sendto return the number of bytes accepted and this number doesn't equal buffer size, I can free only bytes accepted immediately and I have to wait EVFILT_WRITE (kqueue) or EPOLLOUT (Linux) events to continue transmit not accepted bytes and next bytes? Or I have to wait EVFILT_WRITE (kqueue) or EPOLLOUT (Linux) events to free memory of buffer and transmit next bytes?
- Is it correct that if write/send/sendto return EAGAIN (kqueue) or EAGAIN || EWOULDBLOCK (Linux), I can`t free memory of buffer and I have to wait EVFILT_WRITE (kqueue) or EPOLLOUT (Linux) events to retransmit the same bytes?