@@ -210,6 +210,19 @@ namespace HttpServer
210210 #endif
211211 }*/
212212
213+ bool Socket::tcp_nodelay (const bool nodelay) const
214+ {
215+ #ifdef WIN32
216+ int flags = nodelay ? 1 : 0 ;
217+ return 0 == setsockopt (socket_handle, IPPROTO_TCP, TCP_NODELAY, (char *)&flags, sizeof (flags) );
218+ #elif POSIX
219+ int flags = nodelay ? 1 : 0 ;
220+ return 0 == setsockopt (socket_handle, IPPROTO_TCP, TCP_NODELAY, (char *)&flags, sizeof (flags) );
221+ #else
222+ #error "Undefine platform"
223+ #endif
224+ }
225+
213226 size_t Socket::recv (std::vector<std::string::value_type> &buf) const
214227 {
215228 #ifdef WIN32
@@ -328,17 +341,50 @@ namespace HttpServer
328341
329342 if (1 == ::poll (&event, 1 , timeWait.count () ) && event.revents & POLLOUT)
330343 {
331- send_len = ::send (socket_handle, buf.data (), length, MSG_WAITALL | MSG_NOSIGNAL);
344+ send_len = ::send (socket_handle, buf.data (), length, MSG_NOSIGNAL);
332345 }
333346 #else
334347 #error "Undefine platform"
335348 #endif
336349 return send_len;
337350 }
338351
352+ void Socket::nonblock_send_sync () const
353+ {
354+ #ifdef WIN32
355+ WSAPOLLFD event = {
356+ socket_handle,
357+ POLLWRNORM,
358+ 0
359+ };
360+
361+ ::WSAPoll (&event, 1 , ~0 );
362+ #elif POSIX
363+ struct ::pollfd event = {
364+ socket_handle,
365+ POLLOUT,
366+ 0
367+ };
368+
369+ ::poll (&event, 1 , ~0 );
370+ #else
371+ #error "Undefine platform"
372+ #endif
373+ }
374+
339375 Socket &Socket::operator =(const Socket s)
340376 {
341377 socket_handle = s.socket_handle ;
342378 return *this ;
343379 }
344- };
380+
381+ bool Socket::operator ==(const Socket &sock) const
382+ {
383+ return this ->socket_handle == sock.socket_handle ;
384+ }
385+
386+ bool Socket::operator !=(const Socket &sock) const
387+ {
388+ return this ->socket_handle != sock.socket_handle ;
389+ }
390+ };
0 commit comments