2 #include "ace/OS_NS_errno.h"
3 #include "ace/OS_NS_macros.h"
4 #include "ace/OS_NS_sys_uio.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "ace/OS_QoS.h"
7 #include "ace/Global_Macros.h"
8 #include "ace/os_include/netinet/os_in.h"
10 #if defined (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO) \
11 && (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO == 1)
12 #include "ace/OS_NS_string.h"
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 #if defined (ACE_HAS_VOIDPTR_SOCKOPT)
18 typedef void *ACE_SOCKOPT_TYPE1;
19 #elif defined (ACE_HAS_CHARPTR_SOCKOPT)
20 typedef char *ACE_SOCKOPT_TYPE1;
22 typedef const char *ACE_SOCKOPT_TYPE1;
23 #endif /* ACE_HAS_VOIDPTR_SOCKOPT */
26 ACE_OS::accept (ACE_HANDLE handle,
27 struct sockaddr *addr,
30 ACE_OS_TRACE ("ACE_OS::accept");
31 // On a non-blocking socket with no connections to accept, this
32 // system call will return EWOULDBLOCK or EAGAIN, depending on the
33 // platform. UNIX 98 allows either errno, and they may be the same
34 // numeric value. So to make life easier for upper ACE layers as
35 // well as application programmers, always change EAGAIN to
36 // EWOULDBLOCK. Rather than hack the ACE_OSCALL_RETURN macro, it's
37 // handled explicitly here. If the ACE_OSCALL macro ever changes,
38 // this function needs to be reviewed. On Win32, the regular macros
39 // can be used, as this is not an issue.
41 #if defined (ACE_LACKS_ACCEPT)
42 ACE_UNUSED_ARG (handle);
43 ACE_UNUSED_ARG (addr);
44 ACE_UNUSED_ARG (addrlen);
45 ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE);
46 #elif defined (ACE_WIN32)
47 ACE_SOCKCALL_RETURN (::accept ((ACE_SOCKET) handle,
49 (ACE_SOCKET_LEN *) addrlen),
53 # if defined (ACE_HAS_BROKEN_ACCEPT_ADDR)
54 // Apparently some platforms like VxWorks can't correctly deal with
57 # if defined (ACE_HAS_IPV6)
58 sockaddr_in6 fake_addr;
60 sockaddr_in fake_addr;
61 # endif /* ACE_HAS_IPV6 */
65 addrlen = &fake_addrlen;
69 addr = (sockaddr *) &fake_addr;
70 *addrlen = sizeof fake_addr;
72 # endif /* ACE_HAS_BROKEN_ACCEPT_ADDR */
73 ACE_HANDLE ace_result = ::accept ((ACE_SOCKET) handle,
75 (ACE_SOCKET_LEN *) addrlen);
77 # if !(defined (EAGAIN) && defined (EWOULDBLOCK) && EAGAIN == EWOULDBLOCK)
78 // Optimize this code out if we can detect that EAGAIN ==
79 // EWOULDBLOCK at compile time. If we cannot detect equality at
80 // compile-time (e.g. if EAGAIN or EWOULDBLOCK are not preprocessor
81 // macros) perform the check at run-time. The goal is to avoid two
82 // TSS accesses in the _REENTRANT case when EAGAIN == EWOULDBLOCK.
83 if (ace_result == ACE_INVALID_HANDLE
84 # if !defined (EAGAIN) || !defined (EWOULDBLOCK)
85 && EAGAIN != EWOULDBLOCK
86 # endif /* !EAGAIN || !EWOULDBLOCK */
91 # endif /* EAGAIN != EWOULDBLOCK*/
95 #endif /* defined (ACE_WIN32) */
99 ACE_OS::bind (ACE_HANDLE handle, struct sockaddr *addr, int addrlen)
101 ACE_OS_TRACE ("ACE_OS::bind");
102 #if defined (ACE_LACKS_BIND)
103 ACE_UNUSED_ARG (handle);
104 ACE_UNUSED_ARG (addr);
105 ACE_UNUSED_ARG (addrlen);
106 ACE_NOTSUP_RETURN (-1);
107 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS <= 0x640)
108 // VxWorks clears the sin_port member after a successful bind when
109 // sin_addr != INADDR_ANY, so after the bind we do retrieve the
110 // original address so that user code can safely check the addr
111 // after the bind. See bugzilla 3107 for more details
113 ACE_SOCKCALL (::bind ((ACE_SOCKET) handle,
115 (ACE_SOCKET_LEN) addrlen), int, -1, result);
119 return ACE_OS::getsockname (handle, addr, &addrlen);
121 ACE_SOCKCALL_RETURN (::bind ((ACE_SOCKET) handle,
123 (ACE_SOCKET_LEN) addrlen), int, -1);
128 ACE_OS::closesocket (ACE_HANDLE handle)
130 ACE_OS_TRACE ("ACE_OS::closesocket");
131 #if defined (ACE_WIN32) || defined (ACE_MQX)
132 // @note Do not shutdown the write end here. Doing so will break
133 // applications that duplicate a handle on fork(), for
134 // example, and expect to continue writing in the fork()ed
137 ACE_SOCKCALL_RETURN (::closesocket ((SOCKET) handle), int, -1);
139 //FUZZ: disable check_for_lack_ACE_OS
140 return ::close (handle);
141 //FUZZ: enable check_for_lack_ACE_OS
142 #endif /* ACE_WIN32 */
146 ACE_OS::connect (ACE_HANDLE handle,
147 struct sockaddr *addr,
150 ACE_OS_TRACE ("ACE_OS::connect");
151 #if defined (ACE_LACKS_CONNECT)
152 ACE_UNUSED_ARG (handle);
153 ACE_UNUSED_ARG (addr);
154 ACE_UNUSED_ARG (addrlen);
155 ACE_NOTSUP_RETURN (-1);
157 ACE_SOCKCALL_RETURN (::connect ((ACE_SOCKET) handle,
159 (ACE_SOCKET_LEN) addrlen), int, -1);
160 #endif /* ACE_LACKS_CONNECT */
164 ACE_OS::enum_protocols (int *protocols,
165 ACE_Protocol_Info *protocol_buffer,
166 u_long *buffer_length)
168 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
170 ACE_SOCKCALL_RETURN (::WSAEnumProtocols (protocols,
177 ACE_UNUSED_ARG (protocols);
178 ACE_UNUSED_ARG (protocol_buffer);
179 ACE_UNUSED_ARG (buffer_length);
180 ACE_NOTSUP_RETURN (-1);
181 #endif /* ACE_HAS_WINSOCK2 */
185 ACE_OS::getpeername (ACE_HANDLE handle, struct sockaddr *addr,
188 ACE_OS_TRACE ("ACE_OS::getpeername");
190 #if defined (ACE_LACKS_GETPEERNAME)
191 ACE_UNUSED_ARG (handle);
192 ACE_UNUSED_ARG (addr);
193 ACE_UNUSED_ARG (addrlen);
194 ACE_NOTSUP_RETURN (-1);
195 #elif defined (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO) \
196 && (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO == 1)
198 ACE_SOCKCALL (::getpeername ((ACE_SOCKET) handle,
200 (ACE_SOCKET_LEN *) addrlen),
205 // Some platforms, like older versions of the Linux kernel, do not
206 // initialize the sin_zero field since that field is generally only
207 // used for padding/alignment purposes. On those platforms
208 // memcmp()-based comparisons of the sockaddr_in structure, such as
209 // the one in the ACE_INET_Addr equality operator, may fail due to
210 // random bytes in the sin_zero field even though that field is
211 // unused. Prevent equality comparison of two different sockaddr_in
212 // instances that refer to the same socket from failing by
213 // explicitly initializing the sockaddr_in::sin_zero field to a
214 // consistent value, e.g. zero.
215 if (result != -1 && addr->sa_family == AF_INET)
217 ACE_OS::memset (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero,
219 sizeof (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero));
224 ACE_SOCKCALL_RETURN (::getpeername ((ACE_SOCKET) handle,
226 (ACE_SOCKET_LEN *) addrlen),
229 #endif /* ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO */
233 ACE_OS::getsockname (ACE_HANDLE handle,
234 struct sockaddr *addr,
237 ACE_OS_TRACE ("ACE_OS::getsockname");
238 #if defined (ACE_LACKS_GETSOCKNAME)
239 ACE_UNUSED_ARG (handle);
240 ACE_UNUSED_ARG (addr);
241 ACE_UNUSED_ARG (addrlen);
242 ACE_NOTSUP_RETURN (-1);
243 #elif defined (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO) \
244 && (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO == 1)
246 ACE_SOCKCALL (::getsockname ((ACE_SOCKET) handle,
248 (ACE_SOCKET_LEN *) addrlen),
251 // Some platforms, like older versions of the Linux kernel, do not
252 // initialize the sin_zero field since that field is generally only
253 // used for padding/alignment purposes. On those platforms
254 // memcmp()-based comparisons of the sockaddr_in structure, such as
255 // the one in the ACE_INET_Addr equality operator, may fail due to
256 // random bytes in the sin_zero field even though that field is
257 // unused. Prevent equality comparison of two different sockaddr_in
258 // instances that refer to the same socket from failing by
259 // explicitly initializing the sockaddr_in::sin_zero field to a
260 // consistent value, e.g. zero.
261 if (result != -1 && addr->sa_family == AF_INET)
263 ACE_OS::memset (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero,
265 sizeof (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero));
270 ACE_SOCKCALL_RETURN (::getsockname ((ACE_SOCKET) handle,
272 (ACE_SOCKET_LEN *) addrlen),
274 #endif /* ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO */
277 #if !defined(ACE_SOCKOPT_LEN)
278 #define ACE_SOCKOPT_LEN ACE_SOCKET_LEN
282 ACE_OS::getsockopt (ACE_HANDLE handle,
288 ACE_OS_TRACE ("ACE_OS::getsockopt");
289 #if defined (ACE_LACKS_GETSOCKOPT)
290 ACE_UNUSED_ARG (handle);
291 ACE_UNUSED_ARG (level);
292 ACE_UNUSED_ARG (optname);
293 ACE_UNUSED_ARG (optval);
294 ACE_UNUSED_ARG (optlen);
295 ACE_NOTSUP_RETURN (-1);
297 ACE_SOCKCALL_RETURN (::getsockopt ((ACE_SOCKET) handle,
301 (ACE_SOCKOPT_LEN *) optlen),
304 #endif /* ACE_LACKS_GETSOCKOPT */
308 ACE_OS::listen (ACE_HANDLE handle, int backlog)
310 ACE_OS_TRACE ("ACE_OS::listen");
311 #if defined (ACE_LACKS_LISTEN)
312 ACE_UNUSED_ARG (handle);
313 ACE_UNUSED_ARG (backlog);
314 ACE_NOTSUP_RETURN (-1);
316 ACE_SOCKCALL_RETURN (::listen ((ACE_SOCKET) handle, backlog), int, -1);
317 #endif /* ACE_LACKS_LISTEN */
321 ACE_OS::recv (ACE_HANDLE handle, char *buf, size_t len, int flags)
323 ACE_OS_TRACE ("ACE_OS::recv");
325 // On UNIX, a non-blocking socket with no data to receive, this
326 // system call will return EWOULDBLOCK or EAGAIN, depending on the
327 // platform. UNIX 98 allows either errno, and they may be the same
328 // numeric value. So to make life easier for upper ACE layers as
329 // well as application programmers, always change EAGAIN to
330 // EWOULDBLOCK. Rather than hack the ACE_OSCALL_RETURN macro, it's
331 // handled explicitly here. If the ACE_OSCALL macro ever changes,
332 // this function needs to be reviewed. On Win32, the regular macros
333 // can be used, as this is not an issue.
334 #if defined (ACE_LACKS_RECV)
335 ACE_UNUSED_ARG (handle);
336 ACE_UNUSED_ARG (buf);
337 ACE_UNUSED_ARG (len);
338 ACE_UNUSED_ARG (flags);
339 ACE_NOTSUP_RETURN (-1);
340 #elif defined (ACE_WIN32)
341 ACE_SOCKCALL_RETURN (::recv ((ACE_SOCKET) handle, buf,
342 static_cast<int> (len), flags), ssize_t, -1);
345 ace_result_ = ::recv ((ACE_SOCKET) handle, buf, len, flags);
347 # if !(defined (EAGAIN) && defined (EWOULDBLOCK) && EAGAIN == EWOULDBLOCK)
348 // Optimize this code out if we can detect that EAGAIN ==
349 // EWOULDBLOCK at compile time. If we cannot detect equality at
350 // compile-time (e.g. if EAGAIN or EWOULDBLOCK are not preprocessor
351 // macros) perform the check at run-time. The goal is to avoid two
352 // TSS accesses in the _REENTRANT case when EAGAIN == EWOULDBLOCK.
353 if (ace_result_ == -1
354 # if !defined (EAGAIN) || !defined (EWOULDBLOCK)
355 && EAGAIN != EWOULDBLOCK
356 # endif /* !EAGAIN || !EWOULDBLOCK */
361 # endif /* EAGAIN != EWOULDBLOCK*/
364 #endif /* ACE_LACKS_RECV */
368 ACE_OS::recvfrom (ACE_HANDLE handle,
372 struct sockaddr *addr,
375 ACE_OS_TRACE ("ACE_OS::recvfrom");
376 #if defined (ACE_LACKS_RECVFROM)
377 ACE_UNUSED_ARG (handle);
378 ACE_UNUSED_ARG (buf);
379 ACE_UNUSED_ARG (len);
380 ACE_UNUSED_ARG (flags);
381 ACE_UNUSED_ARG (addr);
382 ACE_UNUSED_ARG (addrlen);
383 ACE_NOTSUP_RETURN (-1);
384 #elif defined (ACE_WIN32)
385 int const shortened_len = static_cast<int> (len);
386 int const result = ::recvfrom ((ACE_SOCKET) handle,
391 (ACE_SOCKET_LEN *) addrlen);
392 if (result == SOCKET_ERROR)
394 ACE_OS::set_errno_to_wsa_last_error ();
395 if (errno == WSAEMSGSIZE &&
396 ACE_BIT_ENABLED (flags, MSG_PEEK))
397 return shortened_len;
405 #else /* non Win32 */
406 ACE_SOCKCALL_RETURN (::recvfrom ((ACE_SOCKET) handle,
411 (ACE_SOCKET_LEN *) addrlen),
413 #endif /* ACE_LACKS_RECVFROM */
417 ACE_OS::recvfrom (ACE_HANDLE handle,
420 size_t &number_of_bytes_recvd,
422 struct sockaddr *addr,
424 ACE_OVERLAPPED *overlapped,
425 ACE_OVERLAPPED_COMPLETION_FUNC func)
427 ACE_OS_TRACE ("ACE_OS::recvfrom");
429 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
431 DWORD the_flags = flags;
432 int result = ::WSARecvFrom ((SOCKET) handle,
442 ACE_OS::set_errno_to_wsa_last_error ();
445 number_of_bytes_recvd = static_cast<size_t> (bytes_recvd);
448 ACE_UNUSED_ARG (handle);
449 ACE_UNUSED_ARG (buffers);
450 ACE_UNUSED_ARG (buffer_count);
451 ACE_UNUSED_ARG (number_of_bytes_recvd);
452 ACE_UNUSED_ARG (flags);
453 ACE_UNUSED_ARG (addr);
454 ACE_UNUSED_ARG (addrlen);
455 ACE_UNUSED_ARG (overlapped);
456 ACE_UNUSED_ARG (func);
457 ACE_NOTSUP_RETURN (-1);
458 #endif /* defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) */
462 ACE_OS::recvmsg (ACE_HANDLE handle, struct msghdr *msg, int flags)
464 ACE_OS_TRACE ("ACE_OS::recvmsg");
465 #if !defined (ACE_LACKS_RECVMSG)
466 # if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
467 DWORD bytes_received = 0;
468 int const result = msg->msg_control
469 ? recvmsg_win32_i (handle, msg, flags, bytes_received)
470 : ::WSARecvFrom ((SOCKET) handle,
471 (WSABUF *) msg->msg_iov,
482 ACE_OS::set_errno_to_wsa_last_error ();
486 return bytes_received;
487 # else /* ACE_HAS_WINSOCK2 */
488 ACE_SOCKCALL_RETURN (::recvmsg (handle, msg, flags), ssize_t, -1);
489 # endif /* ACE_HAS_WINSOCK2 */
491 ACE_UNUSED_ARG (flags);
492 ACE_UNUSED_ARG (msg);
493 ACE_UNUSED_ARG (handle);
495 ACE_NOTSUP_RETURN (-1);
496 #endif /* ACE_LACKS_RECVMSG */
500 ACE_OS::recvv (ACE_HANDLE handle,
504 #if defined (ACE_HAS_WINSOCK2)
506 DWORD bytes_received = 0;
509 // Winsock 2 has WSARecv and can do this directly, but Winsock 1 needs
510 // to do the recvs piece-by-piece.
512 # if (ACE_HAS_WINSOCK2 != 0)
514 result = ::WSARecv ((SOCKET) handle,
522 // Step through the buffers requested by caller; for each one, cycle
523 // through reads until it's filled or an error occurs.
524 for (int i = 0; i < n && result > 0; ++i)
526 char *chunkp = buffers[i].iov_base; // Point to part of chunk being read
527 int chunklen = buffers[i].iov_len; // Track how much to read to chunk
528 while (chunklen > 0 && result > 0)
530 result = ::recv ((SOCKET) handle, chunkp, chunklen, 0);
535 bytes_received += result;
539 # endif /* ACE_HAS_WINSOCK2 != 0 */
541 if (result == SOCKET_ERROR)
543 ACE_OS::set_errno_to_wsa_last_error ();
547 return (ssize_t) bytes_received;
549 return ACE_OS::readv (handle, buffers, n);
550 #endif /* ACE_HAS_WINSOCK2 */
554 ACE_OS::send (ACE_HANDLE handle, const char *buf, size_t len, int flags)
556 ACE_OS_TRACE ("ACE_OS::send");
558 // On UNIX, a non-blocking socket with no data to receive, this
559 // system call will return EWOULDBLOCK or EAGAIN, depending on the
560 // platform. UNIX 98 allows either errno, and they may be the same
561 // numeric value. So to make life easier for upper ACE layers as
562 // well as application programmers, always change EAGAIN to
563 // EWOULDBLOCK. Rather than hack the ACE_OSCALL_RETURN macro, it's
564 // handled explicitly here. If the ACE_OSCALL macro ever changes,
565 // this function needs to be reviewed. On Win32, the regular macros
566 // can be used, as this is not an issue.
567 #if defined (ACE_LACKS_SEND)
568 ACE_UNUSED_ARG (handle);
569 ACE_UNUSED_ARG (buf);
570 ACE_UNUSED_ARG (len);
571 ACE_UNUSED_ARG (flags);
572 ACE_NOTSUP_RETURN (-1);
573 #elif defined (ACE_WIN32)
574 ssize_t result = ::send ((ACE_SOCKET) handle,
576 static_cast<int> (len),
580 ACE_OS::set_errno_to_wsa_last_error();
581 if (errno != ENOBUFS)
584 ACE_SOCKCALL_RETURN(send_partial_i(handle, buf, len, flags), ssize_t, -1);
590 # if defined (ACE_MQX)
591 ssize_t const ace_result_ = ::send ((ACE_SOCKET) handle, (void*)buf, len, flags);
593 ssize_t const ace_result_ = ::send ((ACE_SOCKET) handle, buf, len, flags);
596 # if !(defined (EAGAIN) && defined (EWOULDBLOCK) && EAGAIN == EWOULDBLOCK)
597 // Optimize this code out if we can detect that EAGAIN ==
598 // EWOULDBLOCK at compile time. If we cannot detect equality at
599 // compile-time (e.g. if EAGAIN or EWOULDBLOCK are not preprocessor
600 // macros) perform the check at run-time. The goal is to avoid two
601 // TSS accesses in the _REENTRANT case when EAGAIN == EWOULDBLOCK.
602 if (ace_result_ == -1
603 # if !defined (EAGAIN) || !defined (EWOULDBLOCK)
604 && EAGAIN != EWOULDBLOCK
605 # endif /* !EAGAIN || !EWOULDBLOCK */
610 # endif /* EAGAIN != EWOULDBLOCK*/
613 #endif /* defined (ACE_WIN32) */
617 ACE_OS::sendmsg (ACE_HANDLE handle,
618 const struct msghdr *msg,
621 ACE_OS_TRACE ("ACE_OS::sendmsg");
622 #if !defined (ACE_LACKS_SENDMSG)
623 # if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
624 DWORD bytes_sent = 0;
625 int const result = msg->msg_control
626 ? sendmsg_win32_i (handle, msg, flags, bytes_sent)
627 : ::WSASendTo ((SOCKET) handle,
628 (WSABUF *) msg->msg_iov,
639 ACE_OS::set_errno_to_wsa_last_error ();
643 return (ssize_t) bytes_sent;
644 # elif defined (ACE_HAS_NONCONST_SENDMSG)
645 ACE_SOCKCALL_RETURN (::sendmsg (handle,
646 const_cast<struct msghdr *>(msg),
647 flags), ssize_t, -1);
649 ACE_SOCKCALL_RETURN (::sendmsg (handle, msg, flags), ssize_t, -1);
652 ACE_UNUSED_ARG (flags);
653 ACE_UNUSED_ARG (msg);
654 ACE_UNUSED_ARG (handle);
656 ACE_NOTSUP_RETURN (-1);
657 #endif /* ACE_LACKS_SENDMSG */
661 ACE_OS::sendto (ACE_HANDLE handle,
665 const struct sockaddr *addr,
668 ACE_OS_TRACE ("ACE_OS::sendto");
669 #if defined (ACE_LACKS_SENDTO)
670 ACE_UNUSED_ARG (handle);
671 ACE_UNUSED_ARG (buf);
672 ACE_UNUSED_ARG (len);
673 ACE_UNUSED_ARG (flags);
674 ACE_UNUSED_ARG (addr);
675 ACE_UNUSED_ARG (addrlen);
676 ACE_NOTSUP_RETURN (-1);
677 #elif defined (ACE_VXWORKS)
678 ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle,
679 const_cast <char *> (buf),
682 const_cast<struct sockaddr *> (addr),
685 #elif defined (ACE_WIN32)
686 ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle,
688 static_cast<int> (len),
690 const_cast<struct sockaddr *> (addr),
693 #elif defined (ACE_MQX)
694 ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle,
698 const_cast<struct sockaddr *> (addr),
702 ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle,
706 const_cast<struct sockaddr *> (addr),
709 #endif /* ACE_LACKS_SENDTO */
713 ACE_OS::sendto (ACE_HANDLE handle,
714 const iovec *buffers,
716 size_t &number_of_bytes_sent,
718 const struct sockaddr *addr,
720 ACE_OVERLAPPED *overlapped,
721 ACE_OVERLAPPED_COMPLETION_FUNC func)
723 ACE_OS_TRACE ("ACE_OS::sendto");
724 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
725 DWORD bytes_sent = 0;
726 int result = ::WSASendTo ((SOCKET) handle,
736 ACE_OS::set_errno_to_wsa_last_error ();
738 number_of_bytes_sent = static_cast<size_t> (bytes_sent);
739 return (ssize_t) result;
741 ACE_UNUSED_ARG (overlapped);
742 ACE_UNUSED_ARG (func);
744 number_of_bytes_sent = 0;
748 for (int i = 0; i < buffer_count; ++i)
750 result = ACE_OS::sendto (handle,
751 reinterpret_cast<char *> (
752 buffers[i].iov_base),
759 number_of_bytes_sent += static_cast<size_t> (result);
763 #endif /* defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) */
767 ACE_OS::sendv (ACE_HANDLE handle,
768 const iovec *buffers,
771 #if defined (ACE_HAS_WINSOCK2)
772 DWORD bytes_sent = 0;
775 // Winsock 2 has WSASend and can do this directly, but Winsock 1
776 // needs to do the sends one-by-one.
777 # if (ACE_HAS_WINSOCK2 != 0) && !defined (ACE_DONT_USE_WSASEND)
778 result = ::WSASend ((SOCKET) handle,
785 if (result == SOCKET_ERROR)
787 ACE_OS::set_errno_to_wsa_last_error ();
788 if ((errno != ENOBUFS) ||
793 result = sendv_partial_i(handle, buffers, n);
794 if (result == SOCKET_ERROR)
796 ACE_OS::set_errno_to_wsa_last_error ();
799 bytes_sent = static_cast<DWORD>(result);
802 for (int i = 0; i < n; ++i)
804 result = ::send ((SOCKET) handle,
809 if (result == SOCKET_ERROR)
811 // There is a subtle difference in behaviour depending on
812 // whether or not any data was sent. If no data was sent,
813 // then always return -1. Otherwise return bytes_sent.
814 // This gives the caller an opportunity to keep track of
815 // bytes that have already been sent.
820 ACE_OS::set_errno_to_wsa_last_error ();
826 // Gets ignored on error anyway
827 bytes_sent += result;
829 // If the transfer isn't complete just drop out of the loop.
830 if (result < (int)buffers[i].iov_len)
834 # endif /* ACE_HAS_WINSOCK2 != 0 */
836 return (ssize_t) bytes_sent;
838 #elif defined (ACE_MQX)
839 ssize_t bytes_sent = 0;
840 for (int i = 0; i < n; ++i)
842 ssize_t result = ACE_OS::send (handle, buffers[i].iov_base,
843 buffers[i].iov_len, 0);
847 // There is a subtle difference in behaviour depending on
848 // whether or not any data was sent. If no data was sent,
849 // then always return -1. Otherwise return bytes_sent.
850 // This gives the caller an opportunity to keep track of
851 // bytes that have already been sent.
856 // errno should already be set from the ACE_OS::send call.
862 // Gets ignored on error anyway
863 bytes_sent += result;
865 // If the transfer isn't complete just drop out of the loop.
866 if (result < buffers[i].iov_len)
872 #elif defined (ACE_HAS_SOCK_BUF_SIZE_MAX)
874 // Platform limits the maximum socket message size. Pare down the
875 // iovec, if necessary, to obey the limit.
876 iovec local_iov[ACE_IOV_MAX];
879 for (int i = 0; i < n; i++)
881 local_iov[i].iov_base = buffers[i].iov_base;
882 local_iov[i].iov_len = buffers[i].iov_len;
884 new_total = total + buffers[i].iov_len;
885 if (new_total >= ACE_HAS_SOCK_BUF_SIZE_MAX_VALUE)
887 local_iov[i].iov_len = ACE_HAS_SOCK_BUF_SIZE_MAX_VALUE - total;
893 return ACE_OS::writev (handle, local_iov, n);
896 return ACE_OS::writev (handle, buffers, n);
897 #endif /* ACE_HAS_WINSOCK2 */
901 ACE_OS::setsockopt (ACE_HANDLE handle,
907 ACE_OS_TRACE ("ACE_OS::setsockopt");
908 #if defined (ACE_LACKS_SETSOCKOPT)
909 ACE_UNUSED_ARG (handle);
910 ACE_UNUSED_ARG (level);
911 ACE_UNUSED_ARG (optname);
912 ACE_UNUSED_ARG (optval);
913 ACE_UNUSED_ARG (optlen);
914 ACE_NOTSUP_RETURN (-1);
917 ACE_SOCKCALL (::setsockopt ((ACE_SOCKET) handle,
920 (ACE_SOCKOPT_TYPE1) optval,
925 #if defined (WSAEOPNOTSUPP)
926 if (result == -1 && (errno == WSAEOPNOTSUPP || errno == WSAENOPROTOOPT))
929 #endif /* WSAEOPNOTSUPP */
936 ACE_OS::shutdown (ACE_HANDLE handle, int how)
938 ACE_OS_TRACE ("ACE_OS::shutdown");
939 #if defined (ACE_LACKS_SHUTDOWN)
940 ACE_UNUSED_ARG (handle);
941 ACE_UNUSED_ARG (how);
942 ACE_NOTSUP_RETURN (-1);
944 ACE_SOCKCALL_RETURN (::shutdown ((ACE_SOCKET) handle, how), int, -1);
945 #endif /* ACE_LACKS_SHUTDOWN */
948 ACE_INLINE ACE_HANDLE
949 ACE_OS::socket (int domain,
953 ACE_OS_TRACE ("ACE_OS::socket");
954 #if defined (ACE_LACKS_SOCKET)
955 ACE_UNUSED_ARG (domain);
956 ACE_UNUSED_ARG (type);
957 ACE_UNUSED_ARG (proto);
958 ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE);
960 ACE_SOCKCALL_RETURN (::socket (domain,
965 #endif /* ACE_LACKS_SOCKET */
968 ACE_INLINE ACE_HANDLE
969 ACE_OS::socket (int domain,
972 ACE_Protocol_Info *protocolinfo,
976 ACE_OS_TRACE ("ACE_OS::socket");
978 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
979 ACE_SOCKCALL_RETURN (::WSASocket (domain,
988 ACE_UNUSED_ARG (protocolinfo);
990 ACE_UNUSED_ARG (flags);
992 return ACE_OS::socket (domain,
995 #endif /* ACE_HAS_WINSOCK2 */
999 ACE_OS::socketpair (int domain, int type,
1000 int protocol, ACE_HANDLE sv[2])
1002 ACE_OS_TRACE ("ACE_OS::socketpair");
1003 #if defined (ACE_LACKS_SOCKETPAIR)
1004 ACE_UNUSED_ARG (domain);
1005 ACE_UNUSED_ARG (type);
1006 ACE_UNUSED_ARG (protocol);
1007 ACE_UNUSED_ARG (sv);
1009 ACE_NOTSUP_RETURN (-1);
1011 return ::socketpair (domain, type, protocol, sv);
1012 #endif /* ACE_LACKS_SOCKETPAIR */
1015 ACE_INLINE unsigned int
1016 ACE_OS::if_nametoindex (const char *ifname)
1018 ACE_OS_TRACE ("ACE_OS::if_nametoindex");
1019 #ifdef ACE_LACKS_IF_NAMETOINDEX
1020 ACE_UNUSED_ARG (ifname);
1021 ACE_NOTSUP_RETURN (0);
1023 return ::if_nametoindex (ifname);
1024 #endif /* ACE_LACKS_IF_NAMETOINDEX */
1028 ACE_OS::if_indextoname (unsigned int ifindex, char *ifname)
1030 ACE_OS_TRACE ("ACE_OS::if_indextoname");
1031 #ifdef ACE_LACKS_IF_NAMETOINDEX
1032 ACE_UNUSED_ARG (ifindex);
1033 ACE_UNUSED_ARG (ifname);
1034 ACE_NOTSUP_RETURN (0);
1036 return ::if_indextoname (ifindex, ifname);
1037 #endif /* ACE_LACKS_IF_NAMETOINDEX */
1040 ACE_INLINE struct if_nameindex *
1041 ACE_OS::if_nameindex ()
1043 ACE_OS_TRACE ("ACE_OS::if_nameindex");
1044 #ifdef ACE_LACKS_IF_NAMEINDEX
1045 ACE_NOTSUP_RETURN (0);
1047 return ::if_nameindex ();
1048 #endif /* ACE_LACKS_IF_NAMEINDEX */
1052 ACE_OS::if_freenameindex (struct if_nameindex *ptr)
1054 ACE_OS_TRACE ("ACE_OS::if_freenameindex");
1055 #ifdef ACE_LACKS_IF_NAMEINDEX
1056 ACE_UNUSED_ARG (ptr);
1060 ::if_freenameindex (ptr);
1062 #endif /* ACE_LACKS_IF_NAMEINDEX */
1065 ACE_END_VERSIONED_NAMESPACE_DECL