virtual void flush() { assert(fd >= 0); #ifdef TCP_CORK int flag = 0; setsockopt(fd, IPPROTO_TCP, TCP_CORK, &flag , sizeof(flag)); flag = 1; setsockopt(fd, IPPROTO_TCP, TCP_CORK, &flag , sizeof(flag)); #else send(sendBuffer.get(), sendBuffer.size()); sendBuffer.clear(); #endif }
virtual void write(const void *data, const size_t size) { assert(fd >= 0); if (size == 0) return; #ifdef TCP_CORK send(data, size); #else if (size >= SEND_BUFFER_SIZE_LIMIT) { flush(); send(data, size); } else { sendBuffer.add(data, size); if (sendBuffer.size() >= SEND_BUFFER_SIZE_LIMIT) flush(); } #endif }