OS_NS_sys_socket.cpp

Go to the documentation of this file.
00001 // OS_NS_sys_socket.cpp,v 1.8 2006/02/28 00:23:12 shuston Exp
00002 
00003 #include "ace/OS_NS_sys_socket.h"
00004 
00005 ACE_RCSID(ace, OS_NS_sys_socket, "OS_NS_sys_socket.cpp,v 1.8 2006/02/28 00:23:12 shuston Exp")
00006 
00007 #if !defined (ACE_HAS_INLINED_OSCALLS)
00008 # include "ace/OS_NS_sys_socket.inl"
00009 #endif /* ACE_HAS_INLINED_OS_CALLS */
00010 
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 #if defined (ACE_WIN32)
00014 int ACE_OS::socket_initialized_;
00015 #endif /* ACE_WIN32 */
00016 
00017 #if !(defined (ACE_HAS_WINCE) && (UNDER_CE < 500))
00018 ACE_HANDLE
00019 ACE_OS::accept (ACE_HANDLE handle,
00020                 struct sockaddr *addr,
00021                 int *addrlen,
00022                 const ACE_Accept_QoS_Params &qos_params)
00023 {
00024 # if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00025   ACE_SOCKCALL_RETURN (::WSAAccept ((ACE_SOCKET) handle,
00026                                     addr,
00027                                     (ACE_SOCKET_LEN *) addrlen,
00028                                     (LPCONDITIONPROC) qos_params.qos_condition_callback (),
00029                                     qos_params.callback_data ()),
00030                        ACE_HANDLE,
00031                        ACE_INVALID_HANDLE);
00032 # else
00033   ACE_UNUSED_ARG (qos_params);
00034   return ACE_OS::accept (handle,
00035                          addr,
00036                          addrlen);
00037 # endif /* ACE_HAS_WINSOCK2 */
00038 }
00039 
00040 int
00041 ACE_OS::connect (ACE_HANDLE handle,
00042                  const sockaddr *addr,
00043                  int addrlen,
00044                  const ACE_QoS_Params &qos_params)
00045 {
00046   ACE_OS_TRACE ("ACE_OS::connect");
00047 # if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00048   ACE_SOCKCALL_RETURN (::WSAConnect ((ACE_SOCKET) handle,
00049                                      (const sockaddr *) addr,
00050                                      (ACE_SOCKET_LEN) addrlen,
00051                                      (WSABUF *) qos_params.caller_data (),
00052                                      (WSABUF *) qos_params.callee_data (),
00053                                      (QOS *) qos_params.socket_qos (),
00054                                      (QOS *) qos_params.group_socket_qos ()),
00055                        int, -1);
00056 # else
00057   ACE_UNUSED_ARG (qos_params);
00058   return ACE_OS::connect (handle,
00059                           const_cast <sockaddr *> (addr),
00060                           addrlen);
00061 # endif /* ACE_HAS_WINSOCK2 */
00062 }
00063 
00064 ACE_HANDLE
00065 ACE_OS::join_leaf (ACE_HANDLE socket,
00066                    const sockaddr *name,
00067                    int namelen,
00068                    const ACE_QoS_Params &qos_params)
00069 {
00070 # if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00071 
00072   QOS qos;
00073   // Construct the WinSock2 QOS structure.
00074 
00075   qos.SendingFlowspec = *(qos_params.socket_qos ()->sending_flowspec ());
00076   qos.ReceivingFlowspec = *(qos_params.socket_qos ()->receiving_flowspec ());
00077   qos.ProviderSpecific = (WSABUF) qos_params.socket_qos ()->provider_specific ();
00078 
00079   ACE_SOCKCALL_RETURN (::WSAJoinLeaf ((ACE_SOCKET) socket,
00080                                       name,
00081                                       namelen,
00082                                       (WSABUF *) qos_params.caller_data (),
00083                                       (WSABUF *) qos_params.callee_data (),
00084                                       &qos,
00085                                       (QOS *) qos_params.group_socket_qos (),
00086                                       qos_params.flags ()),
00087                        ACE_HANDLE,
00088                        ACE_INVALID_HANDLE);
00089 
00090 # else
00091   ACE_UNUSED_ARG (socket);
00092   ACE_UNUSED_ARG (name);
00093   ACE_UNUSED_ARG (namelen);
00094   ACE_UNUSED_ARG (qos_params);
00095   ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE);
00096 # endif /* ACE_HAS_WINSOCK2 */
00097 }
00098 #endif  /* !(defined (ACE_HAS_WINCE) && (UNDER_CE < 500)) */
00099 
00100 int
00101 ACE_OS::socket_init (int version_high, int version_low)
00102 {
00103 # if defined (ACE_WIN32) && !defined(ACE_DONT_INIT_WINSOCK)
00104   if (ACE_OS::socket_initialized_ == 0)
00105     {
00106       WORD version_requested = MAKEWORD (version_high, version_low);
00107       WSADATA wsa_data;
00108       int error = WSAStartup (version_requested, &wsa_data);
00109 
00110       if (error != 0)
00111 #   if defined (ACE_HAS_WINCE)
00112         {
00113           ACE_TCHAR fmt[] = ACE_LIB_TEXT ("%s failed, WSAGetLastError returned %d");
00114           ACE_TCHAR buf[80];  // @@ Eliminate magic number.
00115           ACE_OS::sprintf (buf, fmt, ACE_LIB_TEXT ("WSAStartup"), error);
00116           ::MessageBox (0, buf, ACE_LIB_TEXT ("WSAStartup failed!"), MB_OK);
00117         }
00118 #   else
00119       ACE_OS::fprintf (stderr,
00120                        "ACE_OS::socket_init; WSAStartup failed, "
00121                          "WSAGetLastError returned %d\n",
00122                        error);
00123 #   endif /* ACE_HAS_WINCE */
00124 
00125       ACE_OS::socket_initialized_ = 1;
00126     }
00127 # else
00128   ACE_UNUSED_ARG (version_high);
00129   ACE_UNUSED_ARG (version_low);
00130 # endif /* ACE_WIN32 */
00131   return 0;
00132 }
00133 
00134 int
00135 ACE_OS::socket_fini (void)
00136 {
00137 # if defined (ACE_WIN32)
00138   if (ACE_OS::socket_initialized_ != 0)
00139     {
00140       if (WSACleanup () != 0)
00141         {
00142           int error = ::WSAGetLastError ();
00143 #   if defined (ACE_HAS_WINCE)
00144           ACE_TCHAR fmt[] = ACE_LIB_TEXT ("%s failed, WSAGetLastError returned %d");
00145           ACE_TCHAR buf[80];  // @@ Eliminate magic number.
00146           ACE_OS::sprintf (buf, fmt, ACE_LIB_TEXT ("WSACleanup"), error);
00147           ::MessageBox (0, buf , ACE_LIB_TEXT ("WSACleanup failed!"), MB_OK);
00148 #   else
00149           ACE_OS::fprintf (stderr,
00150                            "ACE_OS::socket_fini; WSACleanup failed, "
00151                              "WSAGetLastError returned %d\n",
00152                            error);
00153 #   endif /* ACE_HAS_WINCE */
00154         }
00155       ACE_OS::socket_initialized_ = 0;
00156     }
00157 # endif /* ACE_WIN32 */
00158   return 0;
00159 }
00160 
00161 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:58 2006 for ACE by doxygen 1.3.6