ntdll: Add a helper for platform-specific threading initialization.
[wine.git] / dlls / mswsock / mswsock.c
blobc53ecab232dc87230975c3d6eff97fb1aebbf4c8
1 /*
2 * MSWSOCK specific functions
4 * Copyright (C) 2003 André Johansen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winsock2.h"
26 #include "mswsock.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(mswsock);
32 static LPFN_ACCEPTEX acceptex_fn;
33 static LPFN_GETACCEPTEXSOCKADDRS acceptexsockaddrs_fn;
34 static LPFN_TRANSMITFILE transmitfile_fn;
35 static BOOL initialised;
37 /* Get pointers to the ws2_32 implementations.
38 * NOTE: This assumes that ws2_32 contains only one implementation
39 * of these functions, i.e. that you cannot get different functions
40 * back by passing another socket in. If that ever changes, we'll need
41 * to think about associating the functions with the socket and
42 * exposing that information to this dll somehow.
44 static void get_fn(SOCKET s, GUID* guid, FARPROC* fn)
46 FARPROC func;
47 DWORD len;
48 if (!WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, guid, sizeof(*guid),
49 &func, sizeof(func), &len, NULL, NULL))
50 *fn = func;
53 static void get_fn_pointers(SOCKET s)
55 GUID acceptex_guid = WSAID_ACCEPTEX;
56 GUID acceptexsockaddrs_guid = WSAID_GETACCEPTEXSOCKADDRS;
57 GUID transmitfile_guid = WSAID_TRANSMITFILE;
59 get_fn(s, &acceptex_guid, (FARPROC*)&acceptex_fn);
60 get_fn(s, &acceptexsockaddrs_guid, (FARPROC*)&acceptexsockaddrs_fn);
61 get_fn(s, &transmitfile_guid, (FARPROC*)&transmitfile_fn);
62 initialised = TRUE;
65 /***********************************************************************
66 * AcceptEx (MSWSOCK.@)
68 * Accept a new connection, retrieving the connected addresses and initial data.
70 * listener [I] Listening socket
71 * acceptor [I] Socket to accept on
72 * dest [O] Destination for initial data
73 * dest_len [I] Size of dest in bytes
74 * local_addr_len [I] Number of bytes reserved in dest for local address
75 * rem_addr_len [I] Number of bytes reserved in dest for remote address
76 * received [O] Destination for number of bytes of initial data
77 * overlapped [I] For asynchronous execution
79 * RETURNS
80 * Success: TRUE
81 * Failure: FALSE. Use WSAGetLastError() for details of the error.
83 BOOL WINAPI AcceptEx(SOCKET listener, SOCKET acceptor, PVOID dest, DWORD dest_len,
84 DWORD local_addr_len, DWORD rem_addr_len, LPDWORD received,
85 LPOVERLAPPED overlapped)
87 if (!initialised)
88 get_fn_pointers(acceptor);
90 if (!acceptex_fn)
91 return FALSE;
93 return acceptex_fn(listener, acceptor, dest, dest_len, local_addr_len,
94 rem_addr_len, received, overlapped);
97 /***********************************************************************
98 * GetAcceptExSockaddrs (MSWSOCK.@)
100 * Get information about an accepted socket.
102 * data [O] Destination for the first block of data from AcceptEx()
103 * data_len [I] length of data in bytes
104 * local_len [I] Bytes reserved for local addrinfo
105 * rem_len [I] Bytes reserved for remote addrinfo
106 * local_addr [O] Destination for local sockaddr
107 * local_addr_len [I] Size of local_addr
108 * rem_addr [O] Destination for remote sockaddr
109 * rem_addr_len [I] Size of rem_addr
111 * RETURNS
112 * Nothing.
114 VOID WINAPI GetAcceptExSockaddrs(PVOID data, DWORD data_len, DWORD local_len, DWORD rem_len,
115 struct sockaddr **local_addr, LPINT local_addr_len,
116 struct sockaddr **rem_addr, LPINT rem_addr_len)
118 if (acceptexsockaddrs_fn)
119 acceptexsockaddrs_fn(data, data_len, local_len, rem_len,
120 local_addr, local_addr_len, rem_addr, rem_addr_len);
124 /***********************************************************************
125 * TransmitFile (MSWSOCK.@)
127 * Transmit a file over a socket.
129 * PARAMS
130 * s [I] Handle to a connected socket
131 * file [I] Opened file handle for file to send
132 * total_len [I] Total number of file bytes to send
133 * chunk_len [I] Chunk size to send file in (0=default)
134 * overlapped [I] For asynchronous operation
135 * buffers [I] Head/tail data, or NULL if none
136 * flags [I] TF_ Flags from mswsock.h
138 * RETURNS
139 * Success: TRUE
140 * Failure: FALSE. Use WSAGetLastError() for details of the error.
142 BOOL WINAPI TransmitFile(SOCKET s, HANDLE file, DWORD total_len,
143 DWORD chunk_len, LPOVERLAPPED overlapped,
144 LPTRANSMIT_FILE_BUFFERS buffers, DWORD flags)
146 if (!initialised)
147 get_fn_pointers(s);
149 if (!transmitfile_fn)
150 return FALSE;
152 return transmitfile_fn(s, file, total_len, chunk_len, overlapped, buffers, flags);
155 /***********************************************************************
156 * WSARecvEx (MSWSOCK.@)
158 INT WINAPI WSARecvEx(
159 SOCKET s, /* [in] Descriptor identifying a connected socket */
160 char *buf, /* [out] Buffer for the incoming data */
161 INT len, /* [in] Length of buf, in bytes */
162 INT *flags) /* [in/out] Indicator specifying whether the message is
163 fully or partially received for datagram sockets */
165 FIXME("not implemented\n");
167 return SOCKET_ERROR;