ReactOS  r75907
sock.c File Reference
#include <ntstatus.h>
#include <wine/test.h>
#include <winsock2.h>
#include <wine/winternl.h>
#include <ws2tcpip.h>
#include <wsipx.h>
#include <wsnwlink.h>
#include <mswsock.h>
#include <mstcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
Include dependency graph for sock.c:

Go to the source code of this file.

Classes

struct  thread_info
 
struct  sock_info
 
struct  test_params
 
struct  server_params
 
struct  client_params
 
struct  test_setup
 
struct  server_memory
 
struct  client_memory
 
struct  select_thread_params
 
struct  addr_hint_tests
 
struct  async_message
 

Macros

#define _WIN32_WINNT   0x0600
 
#define WIN32_NO_STATUS
 
#define WSA_CMSG_ALIGN(len)   (((len) + sizeof(SIZE_T) - 1) & ~(sizeof(SIZE_T) - 1))
 
#define MAX_CLIENTS   4 /* Max number of clients */
 
#define FIRST_CHAR   'A' /* First character in transferred pattern */
 
#define BIND_SLEEP   10 /* seconds to wait between attempts to bind() */
 
#define BIND_TRIES   6 /* Number of bind() attempts */
 
#define TEST_TIMEOUT
 
#define NUM_UDP_PEERS   3 /* Number of UDP sockets to create and test > 1 */
 
#define NUM_THREADS   3 /* Number of threads to run getservbyname */
 
#define NUM_QUERIES   250 /* Number of getservbyname queries per thread */
 
#define SERVERIP   "127.0.0.1" /* IP to bind to */
 
#define SERVERPORT   9374 /* Port number to bind to */
 
#define wsa_ok(op, cond, msg)
 
#define make_keepalive(k, enable, time, interval)
 
#define SOCKTIMEOUT1
 
#define SOCKTIMEOUT2   997000 /* 997 seconds */
 
#define IP_PKTINFO_LEN   (sizeof(WSACMSGHDR) + WSA_CMSG_ALIGN(sizeof(struct in_pktinfo)))
 
#define STD_STREAM_SOCKET
 
#define FD_ZERO_ALL()   { FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); }
 
#define FD_SET_ALL(s)   { FD_SET(s, &readfds); FD_SET(s, &writefds); FD_SET(s, &exceptfds); }
 
#define WM_SOCKET   (WM_USER+100)
 
#define ok_event_seq   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : ok_event_sequence
 
#define POLL_CLEAR()   ix = 0
 
#define POLL_SET(s, ev)   {fds[ix].fd = s; fds[ix++].events = ev;}
 
#define POLL_ISSET(s, rev)   poll_isset(fds, ix, s, rev)
 
#define compare_file(h, s, o)   compare_file2(h,s,o,__FILE__,__LINE__)
 
#define WM_ASYNCCOMPLETE   (WM_USER + 100)
 

Typedefs

typedef struct thread_info thread_info
 
typedef struct sock_info sock_info
 
typedef struct test_params test_params
 
typedef struct server_params server_params
 
typedef struct client_params client_params
 
typedef struct test_setup test_setup
 
typedef struct server_memory server_memory
 
typedef struct client_memory client_memory
 
typedef struct select_thread_params select_thread_params
 
typedef struct async_message async_message
 

Functions

static void (WINAPI *pfreeaddrinfo)(struct addrinfo *)
 
static int (WINAPI *pgetaddrinfo)(LPCSTR
 
static const ADDRINFOW
PADDRINFOW *static 
PCSTR (WINAPI *pInetNtop)(INT
 
static PCWSTR (WINAPI *pInetNtopW)(INT
 
static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE
 
static DWORD (WINAPI *pGetAdaptersInfo)(PIP_ADAPTER_INFO
 
static SOCKET setup_server_socket (struct sockaddr_in *addr, int *len)
 
static SOCKET setup_connector_socket (struct sockaddr_in *addr, int len, BOOL nonblock)
 
static int tcp_socketpair (SOCKET *src, SOCKET *dst)
 
static void set_so_opentype (BOOL overlapped)
 
static int set_blocking (SOCKET s, BOOL blocking)
 
static void fill_buffer (char *buf, int chunk_size, int n_chunks)
 
static int test_buffer (char *buf, int chunk_size, int n_chunks)
 
static void read_zero_bytes (SOCKET s)
 
static int do_synchronous_send (SOCKET s, char *buf, int buflen, int flags, int sendlen)
 
static int do_synchronous_recv (SOCKET s, char *buf, int buflen, int flags, int recvlen)
 
static int do_synchronous_recvfrom (SOCKET s, char *buf, int buflen, int flags, struct sockaddr *from, int *fromlen, int recvlen)
 
static void check_so_opentype (void)
 
static void compare_addrinfo (ADDRINFO *a, ADDRINFO *b)
 
static void compare_addrinfow (ADDRINFOW *a, ADDRINFOW *b)
 
static void do_bind (SOCKET s, struct sockaddr *addr, int addrlen)
 
static void server_start (server_params *par)
 
static void server_stop (void)
 
static void client_start (client_params *par)
 
static void client_stop (void)
 
static VOID WINAPI simple_server (server_params *par)
 
static VOID WINAPI oob_server (server_params *par)
 
static VOID WINAPI select_server (server_params *par)
 
static VOID WINAPI simple_client (client_params *par)
 
static VOID WINAPI oob_client (client_params *par)
 
static VOID WINAPI simple_mixed_client (client_params *par)
 
static void WINAPI event_client (client_params *par)
 
static void test_WithoutWSAStartup (void)
 
static void test_WithWSAStartup (void)
 
static void Init (void)
 
static void Exit (void)
 
static void StartServer (LPTHREAD_START_ROUTINE routine, test_params *general, server_params *par)
 
static void StartClients (LPTHREAD_START_ROUTINE routine, test_params *general, client_params *par)
 
static void do_test (test_setup *test)
 
static void test_set_getsockopt (void)
 
static void test_so_reuseaddr (void)
 
static void test_ip_pktinfo (void)
 
static void test_UDP (void)
 
static DWORD WINAPI do_getservbyname (void *param)
 
static void test_getservbyname (void)
 
static void test_WSASocket (void)
 
static void test_WSADuplicateSocket (void)
 
static void test_WSAEnumNetworkEvents (void)
 
static void test_WSAAddressToStringA (void)
 
static void test_WSAAddressToStringW (void)
 
static void test_WSAStringToAddressA (void)
 
static void test_WSAStringToAddressW (void)
 
static DWORD WINAPI SelectReadThread (void *param)
 
static DWORD WINAPI SelectCloseThread (void *param)
 
static void test_errors (void)
 
static void test_listen (void)
 
static void test_select (void)
 
static DWORD WINAPI AcceptKillThread (void *param)
 
static int CALLBACK AlwaysDeferConditionFunc (LPWSABUF lpCallerId, LPWSABUF lpCallerData, LPQOS pQos, LPQOS lpGQOS, LPWSABUF lpCalleeId, LPWSABUF lpCalleeData, GROUP *g, DWORD_PTR dwCallbackData)
 
static void test_accept (void)
 
static void test_extendedSocketOptions (void)
 
static void test_getsockname (void)
 
static void test_dns (void)
 
int WINAPI gethostname (char *name, int namelen)
 
static void test_gethostbyname (void)
 
static void test_gethostbyname_hack (void)
 
static void test_gethostname (void)
 
static void test_inet_addr (void)
 
static void test_addr_to_print (void)
 
static void test_inet_pton (void)
 
static void test_ioctlsocket (void)
 
static DWORD WINAPI drain_socket_thread (LPVOID arg)
 
static void test_send (void)
 
static LRESULT CALLBACK ws2_test_WndProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 
static void get_event_details (int event, int *bit, char *name)
 
static const chardbgstr_event_seq (const LPARAM *seq)
 
static chardbgstr_event_seq_result (SOCKET s, WSANETWORKEVENTS *netEvents)
 
static void flush_events (SOCKET s, HANDLE hEvent)
 
static int match_event_sequence (SOCKET s, WSANETWORKEVENTS *netEvents, const LPARAM *seq)
 
static void ok_event_sequence (SOCKET s, HANDLE hEvent, const LPARAM *seq, const LPARAM **broken_seqs, int completelyBroken)
 
static void test_events (int useMessages)
 
static void test_ipv6only (void)
 
static void test_WSASendMsg (void)
 
static void test_WSASendTo (void)
 
static DWORD WINAPI recv_thread (LPVOID arg)
 
static void WINAPI io_completion (DWORD error, DWORD transferred, WSAOVERLAPPED *overlapped, DWORD flags)
 
static void test_WSARecv (void)
 
static BOOL poll_isset (WSAPOLLFD *fds, int max, SOCKET s, int rev)
 
static void test_WSAPoll (void)
 
static void test_GetAddrInfoW (void)
 
static void test_getaddrinfo (void)
 
static void test_ConnectEx (void)
 
static void test_AcceptEx (void)
 
static void test_DisconnectEx (void)
 
static void compare_file2 (HANDLE handle, SOCKET sock, int offset, const char *file, int line)
 
static void test_TransmitFile (void)
 
static void test_getpeername (void)
 
static void test_sioRoutingInterfaceQuery (void)
 
static void test_sioAddressListChange (void)
 
static void test_synchronous_WSAIoctl (void)
 
static HWND create_async_message_window (void)
 
static void wait_for_async_message (HWND hwnd, HANDLE handle)
 
static void test_WSAAsyncGetServByPort (void)
 
static void test_WSAAsyncGetServByName (void)
 
static SOCKET setup_iocp_src (struct sockaddr_in *bindAddress)
 
static void test_completion_port (void)
 
static void test_address_list_query (void)
 
static DWORD WINAPI inet_ntoa_thread_proc (void *param)
 
static void test_inet_ntoa (void)
 
static void test_WSALookupService (void)
 
static void test_WSAEnumNameSpaceProvidersA (void)
 
static void test_WSAEnumNameSpaceProvidersW (void)
 
 START_TEST (sock)
 

Variables

static LPCSTR
 
static LPCWSTR
 
static const ADDRINFOW
PADDRINFOW *static 
LPVOID
 
static const ADDRINFOW
PADDRINFOW *static 
LPSTR
 
static const ADDRINFOW
PADDRINFOW *static 
ULONG
 
static LPWSTR
 
static DWORD
 
static LPHANDLE
 
static LPDWORD
 
static LPWSAQUERYSETW
 
static LPWSANAMESPACE_INFOA
 
static LPWSANAMESPACE_INFOW
 
static INT
 
static PIO_STATUS_BLOCK
 
static PVOID
 
static FILE_INFORMATION_CLASS
 
static PULONG
 
static BOOL
 
static const struct addr_hint_tests hinttests []
 
static DWORD tls
 
static HANDLE thread [1+MAX_CLIENTS]
 
static DWORD thread_id [1+MAX_CLIENTS]
 
static HANDLE server_ready
 
static HANDLE client_ready [MAX_CLIENTS]
 
static int client_id
 
static const LINGER linger_testvals []
 
static test_setup tests []
 
static BOOL drain_pause = FALSE
 
static struct async_messagemessages_received
 
static int completion_called
 

Macro Definition Documentation

#define _WIN32_WINNT   0x0600

Definition at line 24 of file sock.c.

#define BIND_SLEEP   10 /* seconds to wait between attempts to bind() */

Definition at line 45 of file sock.c.

Referenced by do_bind().

#define BIND_TRIES   6 /* Number of bind() attempts */

Definition at line 46 of file sock.c.

Referenced by do_bind().

#define compare_file (   h,
  s,
  o 
)    compare_file2(h,s,o,__FILE__,__LINE__)

Definition at line 8392 of file sock.c.

Referenced by test_TransmitFile().

#define FD_SET_ALL (   s)    { FD_SET(s, &readfds); FD_SET(s, &writefds); FD_SET(s, &exceptfds); }

Definition at line 3765 of file sock.c.

Referenced by test_select().

#define FD_ZERO_ALL ( )    { FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); }

Definition at line 3764 of file sock.c.

Referenced by test_select().

#define FIRST_CHAR   'A' /* First character in transferred pattern */

Definition at line 44 of file sock.c.

Referenced by fill_buffer(), and test_buffer().

Definition at line 1937 of file sock.c.

Referenced by test_ip_pktinfo().

#define make_keepalive (   k,
  enable,
  time,
  interval 
)
Value:
k.onoff = enable; \
k.keepalivetime = time; \
k.keepaliveinterval = interval;
__u16 time
Definition: mkdosfs.c:366
GLboolean enable
Definition: glext.h:11120
int k
Definition: mpi.c:3369

Definition at line 66 of file sock.c.

Referenced by test_ioctlsocket().

#define MAX_CLIENTS   4 /* Max number of clients */
#define NUM_QUERIES   250 /* Number of getservbyname queries per thread */

Definition at line 53 of file sock.c.

Referenced by do_getservbyname().

#define NUM_THREADS   3 /* Number of threads to run getservbyname */

Definition at line 52 of file sock.c.

Referenced by test_getservbyname().

#define NUM_UDP_PEERS   3 /* Number of UDP sockets to create and test > 1 */

Definition at line 50 of file sock.c.

Referenced by test_UDP().

#define ok_event_seq   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : ok_event_sequence

Definition at line 5737 of file sock.c.

Referenced by test_events().

#define POLL_CLEAR ( )    ix = 0

Definition at line 6891 of file sock.c.

Referenced by test_WSAPoll().

#define POLL_ISSET (   s,
  rev 
)    poll_isset(fds, ix, s, rev)

Definition at line 6893 of file sock.c.

Referenced by test_WSAPoll().

#define POLL_SET (   s,
  ev 
)    {fds[ix].fd = s; fds[ix++].events = ev;}

Definition at line 6892 of file sock.c.

Referenced by test_WSAPoll().

#define SERVERIP   "127.0.0.1" /* IP to bind to */

Definition at line 55 of file sock.c.

Referenced by SelectReadThread(), and test_UDP().

#define SERVERPORT   9374 /* Port number to bind to */
#define SOCKTIMEOUT1
Value:
63000 /* 63 seconds. Do not test fractional part because of a
bug in the linux kernel (fixed in 2.6.8) */

Definition at line 1338 of file sock.c.

Referenced by test_set_getsockopt().

#define SOCKTIMEOUT2   997000 /* 997 seconds */

Definition at line 1340 of file sock.c.

Referenced by test_set_getsockopt().

#define STD_STREAM_SOCKET
Value:
0, \
#define SERVERPORT
Definition: sock.c:56
#define SERVERIP
Definition: sock.c:55
#define SOCK_STREAM
Definition: tcpip.h:118

Definition at line 2120 of file sock.c.

#define TEST_TIMEOUT
Value:
30 /* seconds to wait before killing child threads
after server initialization, if something hangs */

Definition at line 47 of file sock.c.

Referenced by do_getservbyname(), do_test(), and test_getservbyname().

#define WIN32_NO_STATUS

Definition at line 27 of file sock.c.

#define WM_ASYNCCOMPLETE   (WM_USER + 100)
#define WM_SOCKET   (WM_USER+100)

Definition at line 5467 of file sock.c.

Referenced by test_events(), and ws2_test_WndProc().

#define WSA_CMSG_ALIGN (   len)    (((len) + sizeof(SIZE_T) - 1) & ~(sizeof(SIZE_T) - 1))

Definition at line 41 of file sock.c.

#define wsa_ok (   op,
  cond,
  msg 
)
Value:
do { \
int tmp, err = 0; \
tmp = op; \
if ( !(cond tmp) ) err = WSAGetLastError(); \
ok ( cond tmp, msg, GetCurrentThreadId(), err); \
} while (0);
UINT op
Definition: effect.c:219
int int int * err
Definition: fci.h:172
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
if(!(yy_init))
Definition: macro.lex.yy.c:704
UINT msg
Definition: msvc.h:92
#define ok(value,...)
Definition: CImage.cpp:33
static int(WINAPI *pgetaddrinfo)(LPCSTR

Definition at line 58 of file sock.c.

Referenced by client_stop(), do_synchronous_recv(), do_synchronous_recvfrom(), do_synchronous_send(), event_client(), oob_client(), oob_server(), select_server(), SelectReadThread(), simple_client(), simple_mixed_client(), simple_server(), and test_AcceptEx().

Typedef Documentation

Function Documentation

static DWORD WINAPI AcceptKillThread ( void param)
static

Definition at line 4149 of file sock.c.

Referenced by test_accept().

4150 {
4151  select_thread_params *par = param;
4152  struct sockaddr_in address;
4153  int len = sizeof(address);
4154  SOCKET client_socket;
4155 
4157  client_socket = accept(par->s, (struct sockaddr*) &address, &len);
4158  if (client_socket != INVALID_SOCKET)
4159  closesocket(client_socket);
4160  par->ReadKilled = (client_socket == INVALID_SOCKET);
4161  return 0;
4162 }
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
#define closesocket
Definition: main.c:50
#define INVALID_SOCKET
Definition: winsock.h:332
GLfloat param
Definition: glext.h:5796
GLuint address
Definition: glext.h:9393
GLenum GLsizei len
Definition: glext.h:6722
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
UINT_PTR SOCKET
Definition: winsock.h:47
static HANDLE server_ready
Definition: sock.c:221
static int CALLBACK AlwaysDeferConditionFunc ( LPWSABUF  lpCallerId,
LPWSABUF  lpCallerData,
LPQOS  pQos,
LPQOS  lpGQOS,
LPWSABUF  lpCalleeId,
LPWSABUF  lpCalleeData,
GROUP g,
DWORD_PTR  dwCallbackData 
)
static

Definition at line 4165 of file sock.c.

Referenced by test_accept(), and test_AcceptEx().

4168 {
4169  return CF_DEFER;
4170 }
#define CF_DEFER
Definition: winsock2.h:415
static void check_so_opentype ( void  )
static

Definition at line 375 of file sock.c.

Referenced by oob_client(), simple_client(), and simple_mixed_client().

376 {
377  int tmp = 1, len;
378  len = sizeof (tmp);
380  ok ( tmp == 0, "check_so_opentype: wrong startup value of SO_OPENTYPE: %d\n", tmp );
381 }
#define SOL_SOCKET
Definition: winsock.h:398
#define INVALID_SOCKET
Definition: winsock.h:332
GLenum GLsizei len
Definition: glext.h:6722
INT WSAAPI getsockopt(IN SOCKET s, IN INT level, IN INT optname, OUT CHAR FAR *optval, IN OUT INT FAR *optlen)
Definition: sockctrl.c:271
#define SO_OPENTYPE
Definition: ws2_32.h:40
#define ok(value,...)
Definition: CImage.cpp:33
static void client_start ( client_params par)
static

Definition at line 505 of file sock.c.

Referenced by event_client(), oob_client(), simple_client(), and simple_mixed_client().

506 {
507  test_params *gen = par->general;
509 
510  TlsSetValue ( tls, mem );
511 
513 
514  mem->s = WSASocketA ( AF_INET, gen->sock_type, gen->sock_prot,
515  NULL, 0, par->sock_flags );
516 
517  mem->addr.sin_family = AF_INET;
518  mem->addr.sin_addr.s_addr = inet_addr ( gen->inet_addr );
519  mem->addr.sin_port = htons ( gen->inet_port );
520 
521  ok ( mem->s != INVALID_SOCKET, "Client: WSASocket failed\n" );
522 
523  mem->send_buf = LocalAlloc ( LPTR, 2 * gen->n_chunks * gen->chunk_size );
524  mem->recv_buf = mem->send_buf + gen->n_chunks * gen->chunk_size;
525  fill_buffer ( mem->send_buf, gen->chunk_size, gen->n_chunks );
526 
528  /* Wait for the other clients to come up */
530 }
#define TRUE
Definition: types.h:120
test_params * general
Definition: sock.c:137
char * recv_buf
Definition: sock.c:166
#define inet_addr(cp)
Definition: inet.h:98
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1221
SOCKET WSAAPI WSASocketA(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOA lpProtocolInfo, IN GROUP g, IN DWORD dwFlags)
Definition: socklife.c:444
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static int client_id
Definition: sock.c:223
int sock_prot
Definition: sock.c:118
smooth NULL
Definition: ftsmooth.c:513
int sock_type
Definition: sock.c:117
#define MAX_CLIENTS
Definition: sock.c:43
struct sockaddr_in addr
Definition: sock.c:164
#define INVALID_SOCKET
Definition: winsock.h:332
SOCKET s
Definition: sock.c:163
const char * inet_addr
Definition: sock.c:119
static void fill_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:300
static HANDLE client_ready[MAX_CLIENTS]
Definition: sock.c:222
short inet_port
Definition: sock.c:120
int n_clients
Definition: sock.c:123
DWORD sock_flags
Definition: sock.c:138
#define min(a, b)
Definition: monoChain.cc:55
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
char * send_buf
Definition: sock.c:165
#define AF_INET
Definition: tcpip.h:117
#define LPTR
Definition: winbase.h:353
#define ok(value,...)
Definition: CImage.cpp:33
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
static DWORD tls
Definition: sock.c:218
static HANDLE server_ready
Definition: sock.c:221
#define htons(x)
Definition: module.h:213
#define INFINITE
Definition: serial.h:102
int n_chunks
Definition: sock.c:122
static void client_stop ( void  )
static

Definition at line 532 of file sock.c.

Referenced by event_client(), oob_client(), simple_client(), and simple_mixed_client().

533 {
535  wsa_ok ( closesocket ( mem->s ), 0 ==, "closesocket error (%x): %d\n" );
536  LocalFree ( mem->send_buf );
537  LocalFree ( mem );
538  ExitThread(0);
539 }
#define closesocket
Definition: main.c:50
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:349
SOCKET s
Definition: sock.c:163
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
char * send_buf
Definition: sock.c:165
static DWORD tls
Definition: sock.c:218
static void compare_addrinfo ( ADDRINFO a,
ADDRINFO b 
)
static

Definition at line 383 of file sock.c.

Referenced by test_getaddrinfo().

384 {
385  for (; a && b ; a = a->ai_next, b = b->ai_next)
386  {
387  ok(a->ai_flags == b->ai_flags,
388  "Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
389  ok(a->ai_family == b->ai_family,
390  "Wrong family %d != %d\n", a->ai_family, b->ai_family);
391  ok(a->ai_socktype == b->ai_socktype,
392  "Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
393  ok(a->ai_protocol == b->ai_protocol,
394  "Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
395  ok(a->ai_addrlen == b->ai_addrlen,
396  "Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
397  ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
398  "Wrong address data\n");
399  if (a->ai_canonname && b->ai_canonname)
400  {
401  ok(!strcmp(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
402  a->ai_canonname, b->ai_canonname);
403  }
404  else
405  ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
406  a->ai_canonname, b->ai_canonname);
407  }
408  ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
409 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define b
Definition: ke_i.h:79
char * ai_canonname
Definition: ws2def.h:670
int ai_protocol
Definition: ws2def.h:668
int ai_socktype
Definition: ws2def.h:667
#define min(a, b)
Definition: monoChain.cc:55
struct addrinfo * ai_next
Definition: ws2def.h:672
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: CImage.cpp:33
size_t ai_addrlen
Definition: ws2def.h:669
int ai_flags
Definition: ws2def.h:665
struct sockaddr * ai_addr
Definition: ws2def.h:671
int ai_family
Definition: ws2def.h:666
static void compare_addrinfow ( ADDRINFOW a,
ADDRINFOW b 
)
static

Definition at line 411 of file sock.c.

Referenced by test_GetAddrInfoW().

412 {
413  for (; a && b ; a = a->ai_next, b = b->ai_next)
414  {
415  ok(a->ai_flags == b->ai_flags,
416  "Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
417  ok(a->ai_family == b->ai_family,
418  "Wrong family %d != %d\n", a->ai_family, b->ai_family);
419  ok(a->ai_socktype == b->ai_socktype,
420  "Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
421  ok(a->ai_protocol == b->ai_protocol,
422  "Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
423  ok(a->ai_addrlen == b->ai_addrlen,
424  "Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
425  ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
426  "Wrong address data\n");
427  if (a->ai_canonname && b->ai_canonname)
428  {
429  ok(!lstrcmpW(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
430  wine_dbgstr_w(a->ai_canonname), wine_dbgstr_w(b->ai_canonname));
431  }
432  else
433  ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
434  a->ai_canonname, b->ai_canonname);
435  }
436  ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
437 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
struct addrinfoW * ai_next
Definition: ws2def.h:683
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
int ai_family
Definition: ws2def.h:677
size_t ai_addrlen
Definition: ws2def.h:680
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: CString.cpp:62
int ai_protocol
Definition: ws2def.h:679
#define b
Definition: ke_i.h:79
int ai_socktype
Definition: ws2def.h:678
int ai_flags
Definition: ws2def.h:676
#define min(a, b)
Definition: monoChain.cc:55
struct sockaddr * ai_addr
Definition: ws2def.h:682
#define ok(value,...)
Definition: CImage.cpp:33
PWSTR ai_canonname
Definition: ws2def.h:681
static void compare_file2 ( HANDLE  handle,
SOCKET  sock,
int  offset,
const char file,
int  line 
)
static

Definition at line 8394 of file sock.c.

8395 {
8396  char buf1[256], buf2[256];
8397  BOOL success;
8398  int i = 0;
8399 
8401  while (1)
8402  {
8403  DWORD n1 = 0, n2 = 0;
8404 
8405  success = ReadFile(handle, buf1, sizeof(buf1), &n1, NULL);
8406  ok_(file,line)(success, "Failed to read from file.\n");
8407  if (success && n1 == 0)
8408  break;
8409  else if(!success)
8410  return;
8411  n2 = recv(sock, buf2, n1, 0);
8412  ok_(file,line)(n1 == n2, "Block %d size mismatch (%d != %d)\n", i, n1, n2);
8413  ok_(file,line)(memcmp(buf1, buf2, n2) == 0, "Block %d failed\n", i);
8414  i++;
8415  }
8416 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:513
Definition: parser.c:48
unsigned int BOOL
Definition: ntddk_ex.h:94
#define success(from, fromstr, to, tostr)
int n1
Definition: dwarfget.c:148
#define FILE_BEGIN
Definition: winbase.h:110
int n2
Definition: dwarfget.c:148
Definition: tcpcore.h:1455
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define ok_(x1, x2)
Definition: CString.cpp:56
GLintptr offset
Definition: glext.h:5920
Definition: fci.c:114
static HWND create_async_message_window ( void  )
static

Definition at line 9074 of file sock.c.

Referenced by test_WSAAsyncGetServByName(), and test_WSAAsyncGetServByPort().

9075 {
9076  static const char class_name[] = "ws2_32 async message window class";
9077 
9078  WNDCLASSEXA wndclass;
9079  HWND hWnd;
9080 
9081  wndclass.cbSize = sizeof(wndclass);
9082  wndclass.style = CS_HREDRAW | CS_VREDRAW;
9083  wndclass.lpfnWndProc = DefWindowProcA;
9084  wndclass.cbClsExtra = 0;
9085  wndclass.cbWndExtra = 0;
9086  wndclass.hInstance = GetModuleHandleA(NULL);
9087  wndclass.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
9089  wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
9090  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
9091  wndclass.lpszClassName = class_name;
9092  wndclass.lpszMenuName = NULL;
9093 
9094  RegisterClassExA(&wndclass);
9095 
9096  hWnd = CreateWindowA(class_name, "ws2_32 async message window", WS_OVERLAPPEDWINDOW,
9097  0, 0, 500, 500, NULL, NULL, GetModuleHandleA(NULL), NULL);
9098  if (!hWnd)
9099  {
9100  ok(0, "failed to create window: %u\n", GetLastError());
9101  return NULL;
9102  }
9103 
9104  return hWnd;
9105 }
UINT style
Definition: winuser.h:3145
LPCSTR lpszMenuName
Definition: winuser.h:3153
HCURSOR hCursor
Definition: winuser.h:3151
WNDPROC lpfnWndProc
Definition: winuser.h:3146
LPCSTR lpszClassName
Definition: winuser.h:3154
HWND hWnd
Definition: settings.c:17
HANDLE HWND
Definition: compat.h:13
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define CS_HREDRAW
Definition: winuser.h:648
#define IDI_APPLICATION
Definition: winuser.h:699
HICON hIconSm
Definition: winuser.h:3155
#define COLOR_WINDOW
Definition: winuser.h:898
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2031
HINSTANCE hInstance
Definition: winuser.h:3149
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4163
smooth NULL
Definition: ftsmooth.c:513
UINT cbSize
Definition: winuser.h:3144
const char * LPCSTR
Definition: xmlstorage.h:183
HBRUSH hbrBackground
Definition: winuser.h:3152
#define CS_VREDRAW
Definition: winuser.h:653
int cbWndExtra
Definition: winuser.h:3148
HICON hIcon
Definition: winuser.h:3150
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:818
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
ATOM WINAPI RegisterClassExA(_In_ CONST WNDCLASSEXA *)
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2061
int cbClsExtra
Definition: winuser.h:3147
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define ok(value,...)
Definition: CImage.cpp:33
static const char* dbgstr_event_seq ( const LPARAM seq)
static

Definition at line 5528 of file sock.c.

Referenced by ok_event_sequence().

5529 {
5530  static char message[1024];
5531  char name[12];
5532  int len = 1;
5533 
5534  message[0] = '[';
5535  message[1] = 0;
5536  while (*seq)
5537  {
5539  len += sprintf(message + len, "%s(%d) ", name, WSAGETSELECTERROR(*seq));
5540  seq++;
5541  }
5542  if (len > 1) len--;
5543  strcpy( message + len, "]" );
5544  return message;
5545 }
Definition: tftpd.h:59
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
#define sprintf(buf, format,...)
Definition: sprintf.c:55
smooth NULL
Definition: ftsmooth.c:513
#define WSAGETSELECTERROR(l)
Definition: winsock.h:482
GLenum GLsizei len
Definition: glext.h:6722
#define WSAGETSELECTEVENT(l)
Definition: winsock.h:481
Definition: name.c:23
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static void get_event_details(int event, int *bit, char *name)
Definition: sock.c:5494
static char* dbgstr_event_seq_result ( SOCKET  s,
WSANETWORKEVENTS netEvents 
)
static

Definition at line 5547 of file sock.c.

Referenced by ok_event_sequence().

5548 {
5549  static char message[1024];
5550  struct async_message *curr = messages_received;
5551  int index, error, bit = 0;
5552  char name[12];
5553  int len = 1;
5554 
5555  message[0] = '[';
5556  message[1] = 0;
5557  while (1)
5558  {
5559  if (netEvents)
5560  {
5561  if (bit >= FD_MAX_EVENTS) break;
5562  if ( !(netEvents->lNetworkEvents & (1 << bit)) )
5563  {
5564  bit++;
5565  continue;
5566  }
5567  get_event_details(1 << bit, &index, name);
5568  error = netEvents->iErrorCode[index];
5569  bit++;
5570  }
5571  else
5572  {
5573  if (!curr) break;
5574  if (curr->socket != s)
5575  {
5576  curr = curr->next;
5577  continue;
5578  }
5580  error = WSAGETSELECTERROR(curr->lparam);
5581  curr = curr->next;
5582  }
5583 
5584  len += sprintf(message + len, "%s(%d) ", name, error);
5585  }
5586  if (len > 1) len--;
5587  strcpy( message + len, "]" );
5588  return message;
5589 }
Definition: tftpd.h:59
#define FD_MAX_EVENTS
Definition: winsock2.h:313
#define error(str)
Definition: mkdosfs.c:1605
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
struct async_message * next
Definition: sock.c:5462
SOCKET socket
Definition: sock.c:5460
static struct async_message * messages_received
Definition: sock.c:5465
#define sprintf(buf, format,...)
Definition: sprintf.c:55
LPARAM lparam
Definition: sock.c:5461
smooth NULL
Definition: ftsmooth.c:513
#define WSAGETSELECTERROR(l)
Definition: winsock.h:482
#define index(s, c)
Definition: various.h:29
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
#define WSAGETSELECTEVENT(l)
Definition: winsock.h:481
int iErrorCode[FD_MAX_EVENTS]
Definition: winsock2.h:644
Definition: name.c:23
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static void get_event_details(int event, int *bit, char *name)
Definition: sock.c:5494
static void do_bind ( SOCKET  s,
struct sockaddr addr,
int  addrlen 
)
static

Definition at line 446 of file sock.c.

Referenced by SelectReadThread(), server_start(), and test_UDP().

447 {
448  int err, wsaerr = 0, n_try = BIND_TRIES;
449 
450  while ( ( err = bind ( s, addr, addrlen ) ) != 0 &&
451  ( wsaerr = WSAGetLastError () ) == WSAEADDRINUSE &&
452  n_try-- >= 0)
453  {
454  trace ( "address in use, waiting ...\n" );
455  Sleep ( 1000 * BIND_SLEEP );
456  }
457  ok ( err == 0, "failed to bind: %d\n", wsaerr );
458 }
#define trace(...)
Definition: kmt_test.h:172
#define BIND_SLEEP
Definition: sock.c:45
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
#define BIND_TRIES
Definition: sock.c:46
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
GLdouble s
Definition: gl.h:2039
#define err(...)
#define ok(value,...)
Definition: CImage.cpp:33
#define WSAEADDRINUSE
Definition: winerror.h:1961
static DWORD WINAPI do_getservbyname ( void param)
static

Definition at line 2283 of file sock.c.

Referenced by test_getservbyname().

2284 {
2285  struct {
2286  const char *name;
2287  const char *proto;
2288  int port;
2289  } serv[2] = { {"domain", "udp", 53}, {"telnet", "tcp", 23} };
2290 
2291  HANDLE *starttest = param;
2292  int i, j;
2293  struct servent *pserv[2];
2294 
2295  ok ( WaitForSingleObject ( *starttest, TEST_TIMEOUT * 1000 ) != WAIT_TIMEOUT,
2296  "test_getservbyname: timeout waiting for start signal\n" );
2297 
2298  /* ensure that necessary buffer resizes are completed */
2299  for ( j = 0; j < 2; j++) {
2300  pserv[j] = getservbyname ( serv[j].name, serv[j].proto );
2301  }
2302 
2303  for ( i = 0; i < NUM_QUERIES / 2; i++ ) {
2304  for ( j = 0; j < 2; j++ ) {
2305  pserv[j] = getservbyname ( serv[j].name, serv[j].proto );
2306  ok ( pserv[j] != NULL || broken(pserv[j] == NULL) /* win8, fixed in win81 */,
2307  "getservbyname could not retrieve information for %s: %d\n", serv[j].name, WSAGetLastError() );
2308  if ( !pserv[j] ) continue;
2309  ok ( pserv[j]->s_port == htons(serv[j].port),
2310  "getservbyname returned the wrong port for %s: %d\n", serv[j].name, ntohs(pserv[j]->s_port) );
2311  ok ( !strcmp ( pserv[j]->s_proto, serv[j].proto ),
2312  "getservbyname returned the wrong protocol for %s: %s\n", serv[j].name, pserv[j]->s_proto );
2313  ok ( !strcmp ( pserv[j]->s_name, serv[j].name ),
2314  "getservbyname returned the wrong name for %s: %s\n", serv[j].name, pserv[j]->s_name );
2315  }
2316 
2317  ok ( pserv[0] == pserv[1] || broken(pserv[0] != pserv[1]) /* win8, fixed in win81 */,
2318  "getservbyname: winsock resized servent buffer when not necessary\n" );
2319  }
2320 
2321  return 0;
2322 }
#define NUM_QUERIES
Definition: sock.c:53
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TEST_TIMEOUT
Definition: sock.c:47
#define ntohs(x)
Definition: module.h:208
GLuint const GLchar * name
Definition: glext.h:6031
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:513
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
PSERVENT WSAAPI getservbyname(IN const char FAR *name, IN const char FAR *proto)
Definition: getxbyxx.c:500
GLfloat param
Definition: glext.h:5796
char * s_name
Definition: winsock.h:159
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define broken(x)
Definition: _sntprintf.h:21
DWORD *typedef HANDLE
Definition: winlogon.h:52
short s_port
Definition: winsock.h:165
Definition: name.c:23
char * s_proto
Definition: winsock.h:166
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: CImage.cpp:33
#define htons(x)
Definition: module.h:213
USHORT port
Definition: uri.c:219
static int do_synchronous_recv ( SOCKET  s,
char buf,
int  buflen,
int  flags,
int  recvlen 
)
static

Definition at line 345 of file sock.c.

Referenced by oob_client(), oob_server(), simple_client(), and simple_server().

346 {
347  char* last = buf + buflen, *p;
348  int n = 1;
349  for ( p = buf; n > 0 && p < last; )
350  {
351  n = recv ( s, p, min ( recvlen, last - p ), flags );
352  if (n > 0) p += n;
353  }
354  wsa_ok ( n, 0 <=, "do_synchronous_recv (%x): error %d:\n" );
355  return p - buf;
356 }
POINT last
Definition: font.c:45
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint n
Definition: s_context.h:57
GLbitfield flags
Definition: glext.h:7161
GLdouble s
Definition: gl.h:2039
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
#define min(a, b)
Definition: monoChain.cc:55
GLfloat GLfloat p
Definition: glext.h:8902
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
static int do_synchronous_recvfrom ( SOCKET  s,
char buf,
int  buflen,
int  flags,
struct sockaddr from,
int fromlen,
int  recvlen 
)
static

Definition at line 358 of file sock.c.

Referenced by simple_mixed_client().

359 {
360  char* last = buf + buflen, *p;
361  int n = 1;
362  for ( p = buf; n > 0 && p < last; )
363  {
364  n = recvfrom ( s, p, min ( recvlen, last - p ), flags, from, fromlen );
365  if (n > 0) p += n;
366  }
367  wsa_ok ( n, 0 <=, "do_synchronous_recv (%x): error %d:\n" );
368  return p - buf;
369 }
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
POINT last
Definition: font.c:45
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint n
Definition: s_context.h:57
GLbitfield flags
Definition: glext.h:7161
GLdouble s
Definition: gl.h:2039
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
#define min(a, b)
Definition: monoChain.cc:55
GLfloat GLfloat p
Definition: glext.h:8902
static int do_synchronous_send ( SOCKET  s,
char buf,
int  buflen,
int  flags,
int  sendlen 
)
static

Definition at line 332 of file sock.c.

Referenced by oob_client(), oob_server(), simple_client(), simple_mixed_client(), and simple_server().

333 {
334  char* last = buf + buflen, *p;
335  int n = 1;
336  for ( p = buf; n > 0 && p < last; )
337  {
338  n = send ( s, p, min ( sendlen, last - p ), flags );
339  if (n > 0) p += n;
340  }
341  wsa_ok ( n, 0 <=, "do_synchronous_send (%x): error %d\n" );
342  return p - buf;
343 }
POINT last
Definition: font.c:45
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint n
Definition: s_context.h:57
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
GLbitfield flags
Definition: glext.h:7161
GLdouble s
Definition: gl.h:2039
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
#define min(a, b)
Definition: monoChain.cc:55
GLfloat GLfloat p
Definition: glext.h:8902
static void do_test ( test_setup test)
static

Definition at line 1295 of file sock.c.

Referenced by START_TEST().

1296 {
1297  DWORD i, n = min (test->general.n_clients, MAX_CLIENTS);
1298  DWORD wait;
1299 
1301  for (i = 0; i <= n; i++)
1303 
1304  StartServer ( test->srv, &test->general, &test->srv_params );
1305  StartClients ( test->clt, &test->general, &test->clt_params );
1307 
1308  wait = WaitForMultipleObjects ( 1 + n, thread, TRUE, 1000 * TEST_TIMEOUT );
1309  ok ( wait <= WAIT_OBJECT_0 + n ,
1310  "some threads have not completed: %x\n", wait );
1311 
1312  if ( ! ( wait <= WAIT_OBJECT_0 + n ) )
1313  {
1314  for (i = 0; i <= n; i++)
1315  {
1316  if ( WaitForSingleObject ( thread[i], 0 ) != WAIT_OBJECT_0 )
1317  {
1318  trace ("terminating thread %08x\n", thread_id[i]);
1319  TerminateThread ( thread [i], 0 );
1320  }
1321  }
1322  }
1324  for (i = 0; i <= n; i++)
1325  CloseHandle ( client_ready[i] );
1326 }
#define trace(...)
Definition: kmt_test.h:172
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define TEST_TIMEOUT
Definition: sock.c:47
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:571
static void StartClients(LPTHREAD_START_ROUTINE routine, test_params *general, client_params *par)
Definition: sock.c:1280
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD DWORD
Definition: winlogon.h:75
static HANDLE thread[1+MAX_CLIENTS]
Definition: sock.c:219
test_params general
Definition: sock.c:145
GLuint n
Definition: s_context.h:57
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:513
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:583
#define MAX_CLIENTS
Definition: sock.c:43
#define WAIT_OBJECT_0
Definition: winbase.h:378
static DWORD thread_id[1+MAX_CLIENTS]
Definition: sock.c:220
server_params srv_params
Definition: sock.c:147
static HANDLE client_ready[MAX_CLIENTS]
Definition: sock.c:222
LPVOID srv
Definition: sock.c:146
client_params clt_params
Definition: sock.c:149
LPVOID clt
Definition: sock.c:148
int n_clients
Definition: sock.c:123
#define min(a, b)
Definition: monoChain.cc:55
static void StartServer(LPTHREAD_START_ROUTINE routine, test_params *general, server_params *par)
Definition: sock.c:1272
#define ok(value,...)
Definition: CImage.cpp:33
static HANDLE server_ready
Definition: sock.c:221
#define INFINITE
Definition: serial.h:102
static DWORD WINAPI drain_socket_thread ( LPVOID  arg)
static

Definition at line 5291 of file sock.c.

Referenced by test_events(), and test_send().

5292 {
5293  char buffer[1024];
5294  SOCKET sock = *(SOCKET*)arg;
5295  int ret;
5296 
5297  while ((ret = recv(sock, buffer, sizeof(buffer), 0)) != 0)
5298  {
5299  if (ret < 0)
5300  {
5302  {
5303  fd_set readset;
5304  FD_ZERO(&readset);
5305  FD_SET(sock, &readset);
5306  select(sock+1, &readset, NULL, NULL, NULL);
5307  while (drain_pause)
5308  Sleep(100);
5309  }
5310  else
5311  break;
5312  }
5313  }
5314  return 0;
5315 }
Definition: winsock.h:66
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
GLuint buffer
Definition: glext.h:5915
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
smooth NULL
Definition: ftsmooth.c:513
static BOOL drain_pause
Definition: sock.c:5290
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
int ret
Definition: tcpcore.h:1455
UINT_PTR SOCKET
Definition: winsock.h:47
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
static DWORD ( WINAPI pGetAdaptersInfo)
static
static void WINAPI event_client ( client_params par)
static

Definition at line 982 of file sock.c.

983 {
984  test_params *gen = par->general;
986  int id = GetCurrentThreadId(), n_expected = gen->n_chunks * gen->chunk_size,
987  tmp, err, n;
988  HANDLE event;
989  WSANETWORKEVENTS wsa_events;
990  char *send_last, *recv_last, *send_p, *recv_p;
992 
993  trace ( "event_client (%x): starting\n", id );
994  client_start ( par );
995  trace ( "event_client (%x): server ready\n", id );
996 
997  mem = TlsGetValue ( tls );
998 
999  /* Prepare event notification for connect, makes socket nonblocking */
1000  event = WSACreateEvent ();
1001  WSAEventSelect ( mem->s, event, FD_CONNECT );
1002  tmp = connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) );
1003  if ( tmp != 0 ) {
1004  err = WSAGetLastError ();
1005  ok ( err == WSAEWOULDBLOCK, "event_client (%x): connect error: %d\n", id, err );
1006  tmp = WaitForSingleObject ( event, INFINITE );
1007  ok ( tmp == WAIT_OBJECT_0, "event_client (%x): wait for connect event failed: %d\n", id, tmp );
1008  err = WSAEnumNetworkEvents ( mem->s, event, &wsa_events );
1009  ok ( err == 0, "event_client (%x): WSAEnumNetworkEvents error: %d\n", id, err );
1010  err = wsa_events.iErrorCode[ FD_CONNECT_BIT ];
1011  ok ( err == 0, "event_client (%x): connect error: %d\n", id, err );
1012  if ( err ) goto out;
1013  }
1014 
1015  trace ( "event_client (%x) connected\n", id );
1016 
1017  WSAEventSelect ( mem->s, event, mask );
1018 
1019  recv_p = mem->recv_buf;
1020  recv_last = mem->recv_buf + n_expected;
1021  send_p = mem->send_buf;
1022  send_last = mem->send_buf + n_expected;
1023 
1024  while ( TRUE )
1025  {
1026  err = WaitForSingleObject ( event, INFINITE );
1027  ok ( err == WAIT_OBJECT_0, "event_client (%x): wait failed\n", id );
1028 
1029  err = WSAEnumNetworkEvents ( mem->s, event, &wsa_events );
1030  ok( err == 0, "event_client (%x): WSAEnumNetworkEvents error: %d\n", id, err );
1031 
1032  if ( wsa_events.lNetworkEvents & FD_WRITE )
1033  {
1034  err = wsa_events.iErrorCode[ FD_WRITE_BIT ];
1035  ok ( err == 0, "event_client (%x): FD_WRITE error code: %d\n", id, err );
1036 
1037  if ( err== 0 )
1038  do
1039  {
1040  n = send ( mem->s, send_p, min ( send_last - send_p, par->buflen ), 0 );
1041  if ( n < 0 )
1042  {
1043  err = WSAGetLastError ();
1044  ok ( err == WSAEWOULDBLOCK, "event_client (%x): send error: %d\n", id, err );
1045  }
1046  else
1047  send_p += n;
1048  }
1049  while ( n >= 0 && send_p < send_last );
1050 
1051  if ( send_p == send_last )
1052  {
1053  trace ( "event_client (%x): all data sent - shutdown\n", id );
1054  shutdown ( mem->s, SD_SEND );
1055  mask &= ~FD_WRITE;
1056  WSAEventSelect ( mem->s, event, mask );
1057  }
1058  }
1059  if ( wsa_events.lNetworkEvents & FD_READ )
1060  {
1061  err = wsa_events.iErrorCode[ FD_READ_BIT ];
1062  ok ( err == 0, "event_client (%x): FD_READ error code: %d\n", id, err );
1063  if ( err != 0 ) break;
1064 
1065  /* First read must succeed */
1066  n = recv ( mem->s, recv_p, min ( recv_last - recv_p, par->buflen ), 0 );
1067  wsa_ok ( n, 0 <=, "event_client (%x): recv error: %d\n" );
1068 
1069  while ( n >= 0 ) {
1070  recv_p += n;
1071  if ( recv_p == recv_last )
1072  {
1073  mask &= ~FD_READ;
1074  trace ( "event_client (%x): all data received\n", id );
1075  WSAEventSelect ( mem->s, event, mask );
1076  break;
1077  }
1078  n = recv ( mem->s, recv_p, min ( recv_last - recv_p, par->buflen ), 0 );
1079  if ( n < 0 && ( err = WSAGetLastError()) != WSAEWOULDBLOCK )
1080  ok ( 0, "event_client (%x): read error: %d\n", id, err );
1081 
1082  }
1083  }
1084  if ( wsa_events.lNetworkEvents & FD_CLOSE )
1085  {
1086  trace ( "event_client (%x): close event\n", id );
1087  err = wsa_events.iErrorCode[ FD_CLOSE_BIT ];
1088  ok ( err == 0, "event_client (%x): FD_CLOSE error code: %d\n", id, err );
1089  break;
1090  }
1091  }
1092 
1093  n = send_p - mem->send_buf;
1094  ok ( send_p == send_last,
1095  "simple_client (%x): sent less data than expected: %d of %d\n", id, n, n_expected );
1096  n = recv_p - mem->recv_buf;
1097  ok ( recv_p == recv_last,
1098  "simple_client (%x): received less data than expected: %d of %d\n", id, n, n_expected );
1099  n = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
1100  ok ( n == -1, "event_client (%x): test pattern error: %d\n", id, n);
1101 
1102 out:
1103  WSACloseEvent ( event );
1104  trace ( "event_client (%x) exiting\n", id );
1105  client_stop ();
1106 }
#define trace(...)
Definition: kmt_test.h:172
#define TRUE
Definition: types.h:120
test_params * general
Definition: sock.c:137
char * recv_buf
Definition: sock.c:166
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define FD_CONNECT
Definition: winsock.h:409
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define FD_CONNECT_BIT
Definition: winsock2.h:301
#define FD_READ
Definition: winsock.h:405
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
#define FD_WRITE
Definition: winsock.h:406
GLuint n
Definition: s_context.h:57
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLint GLuint mask
Definition: glext.h:6028
long LONG
Definition: pedump.c:60
INT WSAAPI WSAEventSelect(IN SOCKET s, IN WSAEVENT hEventObject, IN LONG lNetworkEvents)
Definition: select.c:182
BOOL WSAAPI WSACloseEvent(IN WSAEVENT hEvent)
Definition: event.c:23
#define FD_READ_BIT
Definition: winsock2.h:293
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
#define FD_CLOSE_BIT
Definition: winsock2.h:303
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define WAIT_OBJECT_0
Definition: winbase.h:378
#define FD_CLOSE
Definition: winsock.h:410
struct sockaddr_in addr
Definition: sock.c:164
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
SOCKET s
Definition: sock.c:163
static FILE * out
Definition: regtests2xml.c:44
int buflen
Definition: sock.c:139
INT WSAAPI WSAEnumNetworkEvents(IN SOCKET s, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents)
Definition: event.c:94
#define err(...)
struct _cl_event * event
Definition: glext.h:7739
static void client_start(client_params *par)
Definition: sock.c:505
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
int iErrorCode[FD_MAX_EVENTS]
Definition: winsock2.h:644
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
DWORD *typedef HANDLE
Definition: winlogon.h:52
WSAEVENT WSAAPI WSACreateEvent(VOID)
Definition: event.c:42
#define SD_SEND
Definition: winsock.h:55
#define min(a, b)
Definition: monoChain.cc:55
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
char * send_buf
Definition: sock.c:165
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
#define INFINITE
Definition: serial.h:102
int n_chunks
Definition: sock.c:122
static void client_stop(void)
Definition: sock.c:532
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define FD_WRITE_BIT
Definition: winsock2.h:295
static void Exit ( void  )
static

Definition at line 1263 of file sock.c.

Referenced by _bdf_add_comment(), _bdf_add_property(), _bdf_list_ensure(), _bdf_list_split(), _bdf_parse_glyphs(), _bdf_parse_properties(), _bdf_parse_start(), _bdf_readstream(), _bdf_set_default_spacing(), _Success_(), AcpiDsEvaluateNamePath(), AcpiEvaluateObjectTyped(), AcpiEvOrphanEcRegMethod(), AcpiExCreateMethod(), AcpiExInsertIntoField(), AcpiExReadDataFromField(), AcpiExResolveMultiple(), AcpiHwClearAcpiStatus(), AcpiHwRegisterWrite(), AcpiInstallSciHandler(), AcpiNsCheckReturnValue(), AcpiNsExecModuleCode(), AcpiRsConvertAmlToResource(), AcpiRsConvertResourceToAml(), AcpiTbInstallAndLoadTable(), AcpiUtAllocateOwnerId(), AcpiUtStrtoulBase10(), AcpiUtStrtoulBase16(), af_axis_hints_new_edge(), af_axis_hints_new_segment(), af_face_globals_compute_style_coverage(), af_face_globals_get_metrics(), af_face_globals_new(), af_glyph_hints_reload(), af_latin_hints_apply(), af_latin_hints_compute_edges(), af_latin_hints_compute_segments(), af_latin_metrics_init_widths(), af_loader_embolden_glyph_in_slot(), af_loader_load_glyph(), bdf_cmap_char_next(), bdf_create_property(), BDF_Face_Init(), BDF_Glyph_Load(), bdf_load_font(), cff_blend_build_vector(), cff_blend_doBlend(), cff_charset_compute_cids(), cff_charset_load(), cff_decoder_prepare(), cff_encoding_load(), cff_face_init(), cff_fd_select_get(), cff_font_load(), cff_get_glyph_name(), cff_index_access_element(), cff_index_get_name(), cff_index_get_pointers(), cff_index_init(), cff_index_load_offsets(), CFF_Load_FD_Select(), cff_load_private_dict(), cff_parse_blend(), cff_parse_font_matrix(), cff_parse_integer(), cff_parse_maxstack(), cff_parse_real(), cff_parse_vsindex(), cff_parser_init(), cff_parser_run(), cff_size_init(), cff_subfont_load(), cff_vstore_load(), check_table_dir(), check_type1_format(), cid_face_init(), cid_face_open(), cid_hex_to_binary(), cid_load_glyph(), cid_load_keyword(), cid_parser_new(), cid_read_subrs(), cid_slot_load_glyph(), classic_kern_validate(), CmpCreateLinkNode(), CmpDoCreate(), CmpGetSymbolicLink(), CmpRemoveSubKey(), co_HOOK_CallHooks(), co_IntProcessKeyboardMessage(), co_MsqDispatchOneSentMessage(), CreateDIBitmap(), DefSetText(), DispTdiQueryIpHwAddress(), DoAppSwitch(), EnumHKCRKey(), EnumHKCRValue(), fnt_face_get_dll_font(), FNT_Face_Init(), fnt_font_load(), FNT_Load_Glyph(), FT_Add_Module(), ft_add_renderer(), FT_Attach_Stream(), ft_bitmap_glyph_init(), FT_ClassicKern_Validate(), FT_CMap_New(), FT_DEFINE_GLYPH(), FT_Done_Library(), FT_Face_Properties(), FT_Get_Gasp(), FT_Get_Glyph(), FT_Get_Postscript_Name(), FT_Glyph_Copy(), FT_Glyph_Stroke(), FT_Glyph_StrokeBorder(), FT_Glyph_To_Bitmap(), FT_GlyphLoader_CheckPoints(), FT_GlyphLoader_CheckSubGlyphs(), ft_glyphslot_init(), FT_Load_Glyph(), FT_Lookup_Renderer(), ft_lzwstate_io(), FT_New_GlyphSlot(), FT_New_Size(), ft_open_face_internal(), FT_OpenType_Validate(), FT_Outline_Decompose(), FT_Raccess_Get_DataOffsets(), ft_raster1_render(), ft_raster1_transform(), FT_Set_Renderer(), ft_smooth_render_generic(), ft_smooth_transform(), FT_Stream_EnterFrame(), FT_Stream_New(), FT_Stream_ReadFields(), FT_Stream_TryRead(), ft_stroke_border_get_counts(), ft_stroke_border_grow(), ft_stroker_add_reverse_left(), ft_stroker_cap(), FT_Stroker_ConicTo(), FT_Stroker_CubicTo(), FT_Stroker_EndSubPath(), FT_Stroker_GetBorderCounts(), FT_Stroker_GetCounts(), FT_Stroker_LineTo(), ft_stroker_outside(), FT_Stroker_ParseOutline(), ft_stroker_process_corner(), ft_stroker_subpath_start(), FT_TrueTypeGX_Validate(), ftc_basic_family_load_glyph(), FTC_CMapCache_Lookup(), FTC_ImageCache_Lookup(), FTC_ImageCache_LookupScaler(), FTC_Manager_New(), FTC_Manager_RegisterCache(), FTC_MruList_New(), FTC_SBitCache_Lookup(), FTC_SBitCache_LookupScaler(), ftc_scaler_lookup_size(), FTC_SNode_New(), ftGdiGetTextCharsetInfo(), gxv_feat_registry_validate(), gxv_kern_coverage_validate(), gxv_kern_subtable_validate(), gxv_lcar_partial_validate(), gxv_load_table(), gxv_prop_validate(), gxv_sfntName_validate(), gxv_validate(), gxv_XEntryTable_validate(), hash_insert(), hash_rehash(), Horizontal_Sweep_Drop(), IntCallWindowProcA(), IntCallWindowProcW(), CSettings::Load(), load_truetype_glyph(), main(), MapAnsiQuerySetToUnicode(), MapUnicodeQuerySetToAnsi(), MiDoMappedCopy(), MiDoPoolCopy(), MmPapAllocatePagesInRange(), NtAreMappedFilesTheSame(), NtGdiGetFontUnicodeRanges(), NtGdiGetGlyphOutline(), NtGdiSelectClipPath(), NtGdiSetDIBitsToDeviceInternal(), NtGdiSetPixelFormat(), NtGdiSwapBuffers(), NtSetSystemPowerState(), NtStopProfile(), NtUserAttachThreadInput(), NtUserBuildPropList(), NtUserDeferWindowPos(), NtUserDefSetText(), NtUserDrawCaptionTemp(), NtUserFillWindow(), NtUserFlashWindowEx(), NtUserGetInternalWindowPos(), NtUserGetLayeredWindowAttributes(), NtUserGetObjectInformation(), NtUserMinMaximize(), NtUserPrintWindow(), NtUserRemoveProp(), NtUserSetCursorIconData(), NtUserSetLayeredWindowAttributes(), NtUserSetProp(), NtUserSetSystemCursor(), NtUserTrackPopupMenuEx(), NtUserUpdateLayeredWindow(), NtUserVkKeyScanEx(), otv_load_table(), otv_validate(), parse_blend_axis_types(), parse_blend_design_map(), parse_blend_design_positions(), parse_dict(), parse_fd_array(), parse_weight_vector(), pcf_cmap_char_next(), PCF_Face_Init(), pcf_get_metric(), PCF_Glyph_Load(), pcf_load_font(), pcf_read_TOC(), pfr_aux_name_load(), pfr_cmap_char_next(), pfr_cmap_init(), pfr_extra_item_load_bitmap_info(), pfr_extra_item_load_font_id(), pfr_extra_item_load_kerning_pairs(), pfr_extra_item_load_stem_snaps(), pfr_extra_items_parse(), pfr_face_get_kerning(), pfr_face_init(), pfr_get_advance(), pfr_glyph_curve_to(), pfr_glyph_line_to(), pfr_glyph_load_compound(), pfr_glyph_load_rec(), pfr_glyph_load_simple(), pfr_load_bitmap_metrics(), pfr_log_font_count(), pfr_log_font_load(), pfr_phy_font_load(), pfr_slot_load(), PipCallDriverAddDevice(), PreloadGlobalMessageTable(), PS_Conv_ToFixed(), ps_dimension_add_counter(), ps_dimension_add_t1stem(), ps_dimension_set_mask_bits(), ps_hint_table_alloc(), ps_hints_apply(), ps_mask_set_bit(), ps_mask_table_alloc(), ps_mask_table_last(), ps_mask_table_merge(), ps_mask_table_merge_all(), ps_mask_table_set_bits(), ps_parser_load_field(), ps_parser_load_field_table(), ps_parser_to_bytes(), ps_table_new(), ps_tocoordarray(), ps_tofixedarray(), psh_glyph_init(), psh_hint_table_init(), RegCreateKeyExA(), RegEnumKeyExA(), RegEnumValueA(), RegLoadKeyA(), RegReplaceKeyA(), sfnt_load_face(), START_TEST(), t1_allocate_blend(), t1_cmap_custom_char_next(), t1_cmap_std_char_next(), T1_Face_Init(), T1_Get_MM_Var(), T1_Get_Private_Dict(), T1_Load_Glyph(), t1_load_keyword(), T1_New_Parser(), T1_Open_Face(), T1_Read_Metrics(), T1_Read_PFM(), t1operator_seac(), T42_Face_Init(), t42_load_keyword(), T42_Open_Face(), t42_parse_dict(), t42_parse_sfnts(), t42_parser_init(), tt_face_get_name(), tt_face_goto_table(), tt_face_init(), tt_face_load_any(), tt_face_load_cmap(), tt_face_load_cvt(), tt_face_load_font_dir(), tt_face_load_fpgm(), tt_face_load_gasp(), tt_face_load_generic_header(), tt_face_load_hdmx(), tt_face_load_kern(), tt_face_load_loca(), tt_face_load_maxp(), tt_face_load_name(), tt_face_load_os2(), tt_face_load_pclt(), tt_face_load_prep(), TT_Load_Glyph(), USBH_ChangeIndicationWorker(), USBH_CheckDeviceLanguage(), USBH_CheckHubIdle(), USBH_CreateDevice(), USBH_FdoCleanup(), USBH_FdoPower(), USBH_GetSerialNumberString(), USBH_IoctlGetDescriptor(), USBH_IoctlGetNodeConnectionAttributes(), USBH_IoctlGetNodeConnectionDriverKeyName(), USBH_IoctlGetNodeConnectionInformation(), USBH_IoctlGetNodeName(), USBH_PdoInternalControl(), USBH_PdoQueryDeviceText(), USBH_ResetDevice(), USBH_ResetPortWorker(), USBH_StartHubFdoDevice(), USBH_SyncResetPort(), USBPORT_AllocateCommonBuffer(), USBPORT_FdoPnP(), USBPORT_FindCompanionControllers(), USBPORT_GetSymbolicName(), USBPORT_HandleSelectConfiguration(), USBPORT_MiniportCompleteTransfer(), USBPORT_OpenInterface(), USBPORT_PdoInternalDeviceControl(), USBPORT_SplitBulkInterruptTransfer(), USBPORT_TimerDpc(), UserSetCursorIconData(), Vertical_Sweep_Drop(), woff_open_font(), WsAsyncCheckAndInitThread(), and WsNqLookupServiceBegin().

1264 {
1265  INT ret, err;
1266  TlsFree ( tls );
1267  ret = WSACleanup();
1268  err = WSAGetLastError();
1269  ok ( ret == 0, "WSACleanup failed ret = %d GetLastError is %d\n", ret, err);
1270 }
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
int32_t INT
Definition: typedefs.h:57
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1111
int ret
#define err(...)
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static void fill_buffer ( char buf,
int  chunk_size,
int  n_chunks 
)
static

Definition at line 300 of file sock.c.

Referenced by client_start().

301 {
302  char c, *p;
303  for ( c = FIRST_CHAR, p = buf; c < FIRST_CHAR + n_chunks; c++, p += chunk_size )
304  memset ( p, c, chunk_size );
305 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define FIRST_CHAR
Definition: sock.c:44
#define c
Definition: ke_i.h:80
GLfloat GLfloat p
Definition: glext.h:8902
#define memset(x, y, z)
Definition: compat.h:39
static void flush_events ( SOCKET  s,
HANDLE  hEvent 
)
static

Definition at line 5591 of file sock.c.

Referenced by ok_event_sequence(), and test_events().

5592 {
5593  WSANETWORKEVENTS netEvents;
5594  struct async_message *prev = NULL, *curr = messages_received;
5595  int ret;
5596  DWORD dwRet;
5597 
5599  {
5600  dwRet = WaitForSingleObject(hEvent, 100);
5601  if (dwRet == WAIT_OBJECT_0)
5602  {
5603  ret = WSAEnumNetworkEvents(s, hEvent, &netEvents);
5604  if (ret)
5605  ok(0, "WSAEnumNetworkEvents failed, error %d\n", ret);
5606  }
5607  }
5608  else
5609  {
5610  while (curr)
5611  {
5612  if (curr->socket == s)
5613  {
5614  if (prev) prev->next = curr->next;
5615  else messages_received = curr->next;
5616 
5617  HeapFree(GetProcessHeap(), 0, curr);
5618 
5619  if (prev) curr = prev->next;
5620  else curr = messages_received;
5621  }
5622  else
5623  {
5624  prev = curr;
5625  curr = curr->next;
5626  }
5627  }
5628  }
5629 }
struct async_message * next
Definition: sock.c:5462
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD DWORD
Definition: winlogon.h:75
static struct async_message * messages_received
Definition: sock.c:5465
static HANDLE hEvent
Definition: comm.c:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
smooth NULL
Definition: ftsmooth.c:513
#define WAIT_OBJECT_0
Definition: winbase.h:378
#define GetProcessHeap()
Definition: compat.h:395
INT WSAAPI WSAEnumNetworkEvents(IN SOCKET s, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents)
Definition: event.c:94
int ret
GLdouble s
Definition: gl.h:2039
#define ok(value,...)
Definition: CImage.cpp:33
#define HeapFree(x, y, z)
Definition: compat.h:394
static void get_event_details ( int  event,
int bit,
char name 
)
static

Definition at line 5494 of file sock.c.

Referenced by dbgstr_event_seq(), dbgstr_event_seq_result(), and match_event_sequence().

5495 {
5496  switch (event)
5497  {
5498  case FD_ACCEPT:
5499  if (bit) *bit = FD_ACCEPT_BIT;
5500  if (name) strcpy(name, "FD_ACCEPT");
5501  break;
5502  case FD_CONNECT:
5503  if (bit) *bit = FD_CONNECT_BIT;
5504  if (name) strcpy(name, "FD_CONNECT");
5505  break;
5506  case FD_READ:
5507  if (bit) *bit = FD_READ_BIT;
5508  if (name) strcpy(name, "FD_READ");
5509  break;
5510  case FD_OOB:
5511  if (bit) *bit = FD_OOB_BIT;
5512  if (name) strcpy(name, "FD_OOB");
5513  break;
5514  case FD_WRITE:
5515  if (bit) *bit = FD_WRITE_BIT;
5516  if (name) strcpy(name, "FD_WRITE");
5517  break;
5518  case FD_CLOSE:
5519  if (bit) *bit = FD_CLOSE_BIT;
5520  if (name) strcpy(name, "FD_CLOSE");
5521  break;
5522  default:
5523  if (bit) *bit = -1;
5524  if (name) sprintf(name, "bad%x", event);
5525  }
5526 }
#define FD_ACCEPT
Definition: winsock.h:408
#define FD_CONNECT
Definition: winsock.h:409
#define FD_CONNECT_BIT
Definition: winsock2.h:301
#define FD_READ
Definition: winsock.h:405
#define FD_OOB_BIT
Definition: winsock2.h:297
#define FD_OOB
Definition: winsock.h:407
#define FD_WRITE
Definition: winsock.h:406
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define FD_READ_BIT
Definition: winsock2.h:293
#define FD_CLOSE_BIT
Definition: winsock2.h:303
#define FD_CLOSE
Definition: winsock.h:410
struct _cl_event * event
Definition: glext.h:7739
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
Definition: name.c:23
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define FD_WRITE_BIT
Definition: winsock2.h:295
int WINAPI gethostname ( char name,
int  namelen 
)
static DWORD WINAPI inet_ntoa_thread_proc ( void param)
static

Definition at line 10121 of file sock.c.

Referenced by test_inet_ntoa().

10122 {
10123  ULONG addr;
10124  const char *str;
10125  HANDLE *event = param;
10126 
10127  addr = inet_addr("4.3.2.1");
10128  ok(addr == htonl(0x04030201), "expected 0x04030201, got %08x\n", addr);
10129  str = inet_ntoa(*(struct in_addr *)&addr);
10130  ok(!strcmp(str, "4.3.2.1"), "expected 4.3.2.1, got %s\n", str);
10131 
10132  SetEvent(event[0]);
10133  WaitForSingleObject(event[1], 3000);
10134 
10135  return 0;
10136 }
#define inet_addr(cp)
Definition: inet.h:98
#define htonl(x)
Definition: module.h:212
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
const WCHAR * str
#define inet_ntoa(addr)
Definition: inet.h:100
Definition: tcpip.h:125
GLfloat param
Definition: glext.h:5796
GLenum const GLvoid * addr
Definition: glext.h:9621
struct _cl_event * event
Definition: glext.h:7739
DWORD *typedef HANDLE
Definition: winlogon.h:52
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: CImage.cpp:33
static void Init ( void  )
static

Definition at line 1227 of file sock.c.

Referenced by START_TEST().

1228 {
1229  WORD ver = MAKEWORD (2, 2);
1230  WSADATA data;
1231  HMODULE hws2_32 = GetModuleHandleA("ws2_32.dll"), hiphlpapi;
1232  HMODULE hntdll = GetModuleHandleA("ntdll.dll");
1233 
1234  pfreeaddrinfo = (void *)GetProcAddress(hws2_32, "freeaddrinfo");
1235  pgetaddrinfo = (void *)GetProcAddress(hws2_32, "getaddrinfo");
1236  pFreeAddrInfoW = (void *)GetProcAddress(hws2_32, "FreeAddrInfoW");
1237  pGetAddrInfoW = (void *)GetProcAddress(hws2_32, "GetAddrInfoW");
1238  pInetNtop = (void *)GetProcAddress(hws2_32, "inet_ntop");
1239  pInetNtopW = (void *)GetProcAddress(hws2_32, "InetNtopW");
1240  pInetPtonA = (void *)GetProcAddress(hws2_32, "inet_pton");
1241  pInetPtonW = (void *)GetProcAddress(hws2_32, "InetPtonW");
1242  pWSALookupServiceBeginW = (void *)GetProcAddress(hws2_32, "WSALookupServiceBeginW");
1243  pWSALookupServiceEnd = (void *)GetProcAddress(hws2_32, "WSALookupServiceEnd");
1244  pWSALookupServiceNextW = (void *)GetProcAddress(hws2_32, "WSALookupServiceNextW");
1245  pWSAEnumNameSpaceProvidersA = (void *)GetProcAddress(hws2_32, "WSAEnumNameSpaceProvidersA");
1246  pWSAEnumNameSpaceProvidersW = (void *)GetProcAddress(hws2_32, "WSAEnumNameSpaceProvidersW");
1247  pWSAPoll = (void *)GetProcAddress(hws2_32, "WSAPoll");
1248 
1249  pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
1250  pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
1251 
1252  hiphlpapi = LoadLibraryA("iphlpapi.dll");
1253  if (hiphlpapi)
1254  {
1255  pGetIpForwardTable = (void *)GetProcAddress(hiphlpapi, "GetIpForwardTable");
1256  pGetAdaptersInfo = (void *)GetProcAddress(hiphlpapi, "GetAdaptersInfo");
1257  }
1258 
1259  ok ( WSAStartup ( ver, &data ) == 0, "WSAStartup failed\n" );
1260  tls = TlsAlloc();
1261 }
unsigned short WORD
Definition: ntddk_ex.h:93
#define MAKEWORD(a, b)
Definition: typedefs.h:248
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:818
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1045
static HINSTANCE hntdll
Definition: process.c:64
HANDLE HMODULE
Definition: typedefs.h:76
#define GetProcAddress(x, y)
Definition: compat.h:410
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static void WINAPI io_completion ( DWORD  error,
DWORD  transferred,
WSAOVERLAPPED overlapped,
DWORD  flags 
)
static

Definition at line 6708 of file sock.c.

Referenced by test_WSARecv().

6709 {
6711 }
static int completion_called
Definition: sock.c:6706
static int match_event_sequence ( SOCKET  s,
WSANETWORKEVENTS netEvents,
const LPARAM seq 
)
static

Definition at line 5631 of file sock.c.

Referenced by ok_event_sequence().

5632 {
5633  int event, index, error, events;
5634  struct async_message *curr;
5635 
5636  if (netEvents)
5637  {
5638  events = netEvents->lNetworkEvents;
5639  while (*seq)
5640  {
5641  event = WSAGETSELECTEVENT(*seq);
5642  error = WSAGETSELECTERROR(*seq);
5643  get_event_details(event, &index, NULL);
5644 
5645  if (!(events & event) && index != -1)
5646  return 0;
5647  if (events & event && index != -1)
5648  {
5649  if (netEvents->iErrorCode[index] != error)
5650  return 0;
5651  }
5652  events &= ~event;
5653  seq++;
5654  }
5655  if (events)
5656  return 0;
5657  }
5658  else
5659  {
5660  curr = messages_received;
5661  while (curr)
5662  {
5663  if (curr->socket == s)
5664  {
5665  if (!*seq) return 0;
5666  if (*seq != curr->lparam) return 0;
5667  seq++;
5668  }
5669  curr = curr->next;
5670  }
5671  if (*seq)
5672  return 0;
5673  }
5674  return 1;
5675 }
#define error(str)
Definition: mkdosfs.c:1605
struct async_message * next
Definition: sock.c:5462
SOCKET socket
Definition: sock.c:5460
static struct async_message * messages_received
Definition: sock.c:5465
LPARAM lparam
Definition: sock.c:5461
smooth NULL
Definition: ftsmooth.c:513
#define WSAGETSELECTERROR(l)
Definition: winsock.h:482
#define index(s, c)
Definition: various.h:29
GLdouble s
Definition: gl.h:2039
struct _cl_event * event
Definition: glext.h:7739
#define WSAGETSELECTEVENT(l)
Definition: winsock.h:481
int iErrorCode[FD_MAX_EVENTS]
Definition: winsock2.h:644
HANDLE events[2]
Definition: event.c:4
static void get_event_details(int event, int *bit, char *name)
Definition: sock.c:5494
static NTSTATUS ( WINAPI pNtSetInformationFile)
static
static void ok_event_sequence ( SOCKET  s,
HANDLE  hEvent,
const LPARAM seq,
const LPARAM **  broken_seqs,
int  completelyBroken 
)
static

Definition at line 5678 of file sock.c.

5679 {
5680  MSG msg;
5681  WSANETWORKEVENTS events, *netEvents = NULL;
5682  int ret;
5683  DWORD dwRet;
5684 
5686  {
5687  netEvents = &events;
5688 
5689  dwRet = WaitForSingleObject(hEvent, 200);
5690  if (dwRet == WAIT_OBJECT_0)
5691  {
5692  ret = WSAEnumNetworkEvents(s, hEvent, netEvents);
5693  if (ret)
5694  {
5695  winetest_ok(0, "WSAEnumNetworkEvents failed, error %d\n", ret);
5696  return;
5697  }
5698  }
5699  else
5700  memset(netEvents, 0, sizeof(*netEvents));
5701  }
5702  else
5703  {
5704  Sleep(200);
5705  /* Run the message loop a little */
5706  while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
5707  {
5708  DispatchMessageA(&msg);
5709  }
5710  }
5711 
5712  if (match_event_sequence(s, netEvents, seq))
5713  {
5714  winetest_ok(1, "Sequence matches expected: %s\n", dbgstr_event_seq(seq));
5715  flush_events(s, hEvent);
5716  return;
5717  }
5718 
5719  if (broken_seqs)
5720  {
5721  for (; *broken_seqs; broken_seqs++)
5722  {
5723  if (match_event_sequence(s, netEvents, *broken_seqs))
5724  {
5725  winetest_ok(broken(1), "Sequence matches broken: %s, expected %s\n", dbgstr_event_seq_result(s, netEvents), dbgstr_event_seq(seq));
5726  flush_events(s, hEvent);
5727  return;
5728  }
5729  }
5730  }
5731 
5732  winetest_ok(broken(completelyBroken), "Expected event sequence %s, got %s\n", dbgstr_event_seq(seq),
5733  dbgstr_event_seq_result(s, netEvents));
5734  flush_events(s, hEvent);
5735 }
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static const char * dbgstr_event_seq(const LPARAM *seq)
Definition: sock.c:5528
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
BOOL WINAPI PeekMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
DWORD DWORD
Definition: winlogon.h:75
static HANDLE hEvent
Definition: comm.c:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
smooth NULL
Definition: ftsmooth.c:513
#define WAIT_OBJECT_0
Definition: winbase.h:378
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
INT WSAAPI WSAEnumNetworkEvents(IN SOCKET s, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents)
Definition: event.c:94
int ret
static char * dbgstr_event_seq_result(SOCKET s, WSANETWORKEVENTS *netEvents)
Definition: sock.c:5547
GLdouble s
Definition: gl.h:2039
#define broken(x)
Definition: _sntprintf.h:21
static void flush_events(SOCKET s, HANDLE hEvent)
Definition: sock.c:5591
HANDLE events[2]
Definition: event.c:4
#define msg(x)
Definition: auth_time.c:54
static int match_event_sequence(SOCKET s, WSANETWORKEVENTS *netEvents, const LPARAM *seq)
Definition: sock.c:5631
#define PM_REMOVE
Definition: winuser.h:1172
#define memset(x, y, z)
Definition: compat.h:39
static VOID WINAPI oob_client ( client_params par)
static

Definition at line 860 of file sock.c.

861 {
862  test_params *gen = par->general;
864  int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
865 
866  id = GetCurrentThreadId();
867  trace ( "oob_client (%x): starting\n", id );
868  /* wait here because we want to call set_so_opentype before creating a socket */
870  trace ( "oob_client (%x): server ready\n", id );
871 
873  set_so_opentype ( FALSE ); /* non-overlapped */
874  client_start ( par );
875  mem = TlsGetValue ( tls );
876 
877  /* Connect */
878  wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
879  0 ==, "oob_client (%x): connect error: %d\n" );
880  ok ( set_blocking ( mem->s, TRUE ) == 0,
881  "oob_client (%x): failed to set blocking mode\n", id );
882  trace ( "oob_client (%x) connected\n", id );
883 
884  /* send data to server */
885  n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, 0, par->buflen );
886  ok ( n_sent == n_expected,
887  "oob_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
888 
889  /* Receive data echoed back & check it */
890  n_recvd = do_synchronous_recv ( mem->s, mem->recv_buf, n_expected, 0, par->buflen );
891  ok ( n_recvd == n_expected,
892  "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
893  pos = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
894  ok ( pos == -1, "simple_client (%x): test pattern error: %d\n", id, pos);
895 
896  /* send out-of-band data to server */
897  n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, MSG_OOB, par->buflen );
898  ok ( n_sent == n_expected,
899  "oob_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
900 
901  /* shutdown send direction */
902  wsa_ok ( shutdown ( mem->s, SD_SEND ), 0 ==, "simple_client (%x): shutdown failed: %d\n" );
903 
904  /* cleanup */
905  read_zero_bytes ( mem->s );
906  trace ( "oob_client (%x) exiting\n", id );
907  client_stop ();
908 }
#define trace(...)
Definition: kmt_test.h:172
#define TRUE
Definition: types.h:120
test_params * general
Definition: sock.c:137
char * recv_buf
Definition: sock.c:166
static void check_so_opentype(void)
Definition: sock.c:375
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define MSG_OOB
Definition: winsock.h:221
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
struct sockaddr_in addr
Definition: sock.c:164
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
SOCKET s
Definition: sock.c:163
int buflen
Definition: sock.c:139
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:281
static void read_zero_bytes(SOCKET s)
Definition: sock.c:323
static void client_start(client_params *par)
Definition: sock.c:505
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
#define SD_SEND
Definition: winsock.h:55
static int do_synchronous_recv(SOCKET s, char *buf, int buflen, int flags, int recvlen)
Definition: sock.c:345
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
char * send_buf
Definition: sock.c:165
GLenum GLuint id
Definition: glext.h:5579
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static int do_synchronous_send(SOCKET s, char *buf, int buflen, int flags, int sendlen)
Definition: sock.c:332
static HANDLE server_ready
Definition: sock.c:221
#define INFINITE
Definition: serial.h:102
int n_chunks
Definition: sock.c:122
static void client_stop(void)
Definition: sock.c:532
static VOID WINAPI oob_server ( server_params par)
static

Definition at line 602 of file sock.c.

603 {
604  test_params *gen = par->general;
606  u_long atmark = 0;
607  int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, tmp,
608  id = GetCurrentThreadId();
609 
610  trace ( "oob_server (%x) starting\n", id );
611 
612  set_so_opentype ( FALSE ); /* non-overlapped */
613  server_start ( par );
614  mem = TlsGetValue ( tls );
615 
616  wsa_ok ( set_blocking ( mem->s, TRUE ), 0 ==, "oob_server (%x): failed to set blocking mode: %d\n");
617  wsa_ok ( listen ( mem->s, SOMAXCONN ), 0 ==, "oob_server (%x): listen failed: %d\n");
618 
619  trace ( "oob_server (%x) ready\n", id );
620  SetEvent ( server_ready ); /* notify clients */
621 
622  trace ( "oob_server (%x): waiting for client\n", id );
623 
624  /* accept a single connection */
625  tmp = sizeof ( mem->sock[0].peer );
626  mem->sock[0].s = accept ( mem->s, (struct sockaddr*) &mem->sock[0].peer, &tmp );
627  wsa_ok ( mem->sock[0].s, INVALID_SOCKET !=, "oob_server (%x): accept failed: %d\n" );
628 
629  ok ( mem->sock[0].peer.sin_addr.s_addr == inet_addr ( gen->inet_addr ),
630  "oob_server (%x): strange peer address\n", id );
631 
632  /* check initial atmark state */
633  ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
634  ok ( atmark == 1, "oob_server (%x): unexpectedly at the OOB mark: %i\n", id, atmark );
635 
636  /* Receive normal data */
637  n_recvd = do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
638  ok ( n_recvd == n_expected,
639  "oob_server (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
640  pos = test_buffer ( mem->sock[0].buf, gen->chunk_size, gen->n_chunks );
641  ok ( pos == -1, "oob_server (%x): test pattern error: %d\n", id, pos);
642 
643  /* check atmark state */
644  ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
645  ok ( atmark == 1, "oob_server (%x): unexpectedly at the OOB mark: %i\n", id, atmark );
646 
647  /* Echo data back */
648  n_sent = do_synchronous_send ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
649  ok ( n_sent == n_expected,
650  "oob_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
651 
652  /* Receive a part of the out-of-band data and print atmark state */
653  n_recvd = do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, 8, 0, par->buflen );
654  ok ( n_recvd == 8,
655  "oob_server (%x): received less data than expected: %d of %d\n", id, n_recvd, 8 );
656  n_expected -= 8;
657 
658  ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
659  trace( "oob_server (%x): %s the OOB mark: %i\n", id, atmark == 1 ? "not at" : "at", atmark );
660 
661  /* Receive the rest of the out-of-band data and check atmark state */
662  do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
663 
664  ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
665  todo_wine ok ( atmark == 0, "oob_server (%x): not at the OOB mark: %i\n", id, atmark );
666 
667  /* cleanup */
668  wsa_ok ( closesocket ( mem->sock[0].s ), 0 ==, "oob_server (%x): closesocket error: %d\n" );
669  mem->sock[0].s = INVALID_SOCKET;
670 
671  trace ( "oob_server (%x) exiting\n", id );
672  server_stop ();
673 }
#define trace(...)
Definition: kmt_test.h:172
#define SIOCATMARK
Definition: winsock.h:253
#define TRUE
Definition: types.h:120
unsigned long u_long
Definition: linux.h:269
#define inet_addr(cp)
Definition: inet.h:98
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
SOCKET s
Definition: sock.c:106
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
char * buf
Definition: sock.c:109
#define SOMAXCONN
Definition: winsock.h:399
#define closesocket
Definition: main.c:50
#define FALSE
Definition: types.h:117
static void server_start(server_params *par)
Definition: sock.c:460
SOCKET s
Definition: sock.c:155
test_params * general
Definition: sock.c:129
#define ioctlsocket
Definition: main.c:51
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
#define INVALID_SOCKET
Definition: winsock.h:332
const char * inet_addr
Definition: sock.c:119
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:281
#define todo_wine
Definition: test.h:154
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
int buflen
Definition: sock.c:131
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
struct sockaddr_in peer
Definition: sock.c:108
sock_info sock[MAX_CLIENTS]
Definition: sock.c:157
static int do_synchronous_recv(SOCKET s, char *buf, int buflen, int flags, int recvlen)
Definition: sock.c:345
static void server_stop(void)
Definition: sock.c:487
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static int do_synchronous_send(SOCKET s, char *buf, int buflen, int flags, int sendlen)
Definition: sock.c:332
static HANDLE server_ready
Definition: sock.c:221
int n_chunks
Definition: sock.c:122
static const ADDRINFOW PADDRINFOW* static PCSTR ( WINAPI pInetNtop)
static
static PCWSTR ( WINAPI pInetNtopW)
static
static BOOL poll_isset ( WSAPOLLFD *  fds,
int  max,
SOCKET  s,
int  rev 
)
static

Definition at line 6894 of file sock.c.

6895 {
6896  int k;
6897  for (k = 0; k < max; k++)
6898  if (fds[k].fd == s && (fds[k].revents == rev)) return TRUE;
6899  return FALSE;
6900 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
int rev
Definition: sort.c:17
GLdouble s
Definition: gl.h:2039
static HANDLE fd
Definition: io.c:55
int k
Definition: mpi.c:3369
static void read_zero_bytes ( SOCKET  s)
static

Definition at line 323 of file sock.c.

Referenced by oob_client(), select_server(), simple_client(), simple_mixed_client(), and simple_server().

324 {
325  char buf[256];
326  int tmp, n = 0;
327  while ( ( tmp = recv ( s, buf, 256, 0 ) ) > 0 )
328  n += tmp;
329  ok ( n <= 0, "garbage data received: %d bytes\n", n );
330 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint n
Definition: s_context.h:57
GLdouble s
Definition: gl.h:2039
#define ok(value,...)
Definition: CImage.cpp:33
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
static DWORD WINAPI recv_thread ( LPVOID  arg)
static

Definition at line 6688 of file sock.c.

Referenced by test_WSARecv().

6689 {
6690  SOCKET sock = *(SOCKET *)arg;
6691  char buffer[32];
6692  WSABUF wsa;
6693  WSAOVERLAPPED ov;
6694  DWORD flags = 0;
6695 
6696  wsa.buf = buffer;
6697  wsa.len = sizeof(buffer);
6698  ov.hEvent = WSACreateEvent();
6699  WSARecv(sock, &wsa, 1, NULL, &flags, &ov, NULL);
6700 
6701  WaitForSingleObject(ov.hEvent, 1000);
6702  WSACloseEvent(ov.hEvent);
6703  return 0;
6704 }
GLuint buffer
Definition: glext.h:5915
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WSAAPI WSACloseEvent(IN WSAEVENT hEvent)
Definition: event.c:23
smooth NULL
Definition: ftsmooth.c:513
ULONG len
Definition: ws2def.h:519
GLbitfield flags
Definition: glext.h:7161
CHAR FAR * buf
Definition: ws2def.h:520
INT WSAAPI WSARecv(IN SOCKET s, IN OUT LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesRecvd, IN OUT LPDWORD lpFlags, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: recv.c:155
WSAEVENT WSAAPI WSACreateEvent(VOID)
Definition: event.c:42
#define WSAOVERLAPPED
Definition: winsock2.h:587
Definition: tcpcore.h:1455
UINT_PTR SOCKET
Definition: winsock.h:47
static VOID WINAPI select_server ( server_params par)
static

Definition at line 678 of file sock.c.

679 {
680  test_params *gen = par->general;
682  int n_expected = gen->n_chunks * gen->chunk_size, tmp, i,
683  id = GetCurrentThreadId(), n_connections = 0, n_sent, n_recvd,
684  n_set, delta, n_ready;
685  struct timeval timeout = {0,10}; /* wait for 10 milliseconds */
686  fd_set fds_recv, fds_send, fds_openrecv, fds_opensend;
687 
688  trace ( "select_server (%x) starting\n", id );
689 
690  set_so_opentype ( FALSE ); /* non-overlapped */
691  server_start ( par );
692  mem = TlsGetValue ( tls );
693 
694  wsa_ok ( set_blocking ( mem->s, FALSE ), 0 ==, "select_server (%x): failed to set blocking mode: %d\n");
695  wsa_ok ( listen ( mem->s, SOMAXCONN ), 0 ==, "select_server (%x): listen failed: %d\n");
696 
697  trace ( "select_server (%x) ready\n", id );
698  SetEvent ( server_ready ); /* notify clients */
699 
700  FD_ZERO ( &fds_openrecv );
701  FD_ZERO ( &fds_recv );
702  FD_ZERO ( &fds_send );
703  FD_ZERO ( &fds_opensend );
704 
705  FD_SET ( mem->s, &fds_openrecv );
706 
707  while(1)
708  {
709  fds_recv = fds_openrecv;
710  fds_send = fds_opensend;
711 
712  n_set = 0;
713 
714  wsa_ok ( ( n_ready = select ( 0, &fds_recv, &fds_send, NULL, &timeout ) ), SOCKET_ERROR !=,
715  "select_server (%x): select() failed: %d\n" );
716 
717  /* check for incoming requests */
718  if ( FD_ISSET ( mem->s, &fds_recv ) ) {
719  n_set += 1;
720 
721  trace ( "select_server (%x): accepting client connection\n", id );
722 
723  /* accept a single connection */
724  tmp = sizeof ( mem->sock[n_connections].peer );
725  mem->sock[n_connections].s = accept ( mem->s, (struct sockaddr*) &mem->sock[n_connections].peer, &tmp );
726  wsa_ok ( mem->sock[n_connections].s, INVALID_SOCKET !=, "select_server (%x): accept() failed: %d\n" );
727 
728  ok ( mem->sock[n_connections].peer.sin_addr.s_addr == inet_addr ( gen->inet_addr ),
729  "select_server (%x): strange peer address\n", id );
730 
731  /* add to list of open connections */
732  FD_SET ( mem->sock[n_connections].s, &fds_openrecv );
733  FD_SET ( mem->sock[n_connections].s, &fds_opensend );
734 
735  n_connections++;
736  }
737 
738  /* handle open requests */
739 
740  for ( i = 0; i < n_connections; i++ )
741  {
742  if ( FD_ISSET( mem->sock[i].s, &fds_recv ) ) {
743  n_set += 1;
744 
745  if ( mem->sock[i].n_recvd < n_expected ) {
746  /* Receive data & check it */
747  n_recvd = recv ( mem->sock[i].s, mem->sock[i].buf + mem->sock[i].n_recvd, min ( n_expected - mem->sock[i].n_recvd, par->buflen ), 0 );
748  ok ( n_recvd != SOCKET_ERROR, "select_server (%x): error in recv(): %d\n", id, WSAGetLastError() );
749  mem->sock[i].n_recvd += n_recvd;
750 
751  if ( mem->sock[i].n_recvd == n_expected ) {
752  int pos = test_buffer ( mem->sock[i].buf, gen->chunk_size, gen->n_chunks );
753  ok ( pos == -1, "select_server (%x): test pattern error: %d\n", id, pos );
754  FD_CLR ( mem->sock[i].s, &fds_openrecv );
755  }
756 
757  ok ( mem->sock[i].n_recvd <= n_expected, "select_server (%x): received too many bytes: %d\n", id, mem->sock[i].n_recvd );
758  }
759  }
760 
761  /* only echo back what we've received */
762  delta = mem->sock[i].n_recvd - mem->sock[i].n_sent;
763 
764  if ( FD_ISSET ( mem->sock[i].s, &fds_send ) ) {
765  n_set += 1;
766 
767  if ( ( delta > 0 ) && ( mem->sock[i].n_sent < n_expected ) ) {
768  /* Echo data back */
769  n_sent = send ( mem->sock[i].s, mem->sock[i].buf + mem->sock[i].n_sent, min ( delta, par->buflen ), 0 );
770  ok ( n_sent != SOCKET_ERROR, "select_server (%x): error in send(): %d\n", id, WSAGetLastError() );
771  mem->sock[i].n_sent += n_sent;
772 
773  if ( mem->sock[i].n_sent == n_expected ) {
774  FD_CLR ( mem->sock[i].s, &fds_opensend );
775  }
776 
777  ok ( mem->sock[i].n_sent <= n_expected, "select_server (%x): sent too many bytes: %d\n", id, mem->sock[i].n_sent );
778  }
779  }
780  }
781 
782  /* check that select returned the correct number of ready sockets */
783  ok ( ( n_set == n_ready ), "select_server (%x): select() returns wrong number of ready sockets\n", id );
784 
785  /* check if all clients are done */
786  if ( ( fds_opensend.fd_count == 0 )
787  && ( fds_openrecv.fd_count == 1 ) /* initial socket that accepts clients */
788  && ( n_connections == min ( gen->n_clients, MAX_CLIENTS ) ) ) {
789  break;
790  }
791  }
792 
793  for ( i = 0; i < min ( gen->n_clients, MAX_CLIENTS ); i++ )
794  {
795  /* cleanup */
796  read_zero_bytes ( mem->sock[i].s );
797  wsa_ok ( closesocket ( mem->sock[i].s ), 0 ==, "select_server (%x): closesocket error: %d\n" );
798  mem->sock[i].s = INVALID_SOCKET;
799  }
800 
801  trace ( "select_server (%x) exiting\n", id );
802  server_stop ();
803 }
Definition: winsock.h:66
#define SOCKET_ERROR
Definition: winsock.h:333
#define trace(...)
Definition: kmt_test.h:172
#define inet_addr(cp)
Definition: inet.h:98
int n_recvd
Definition: sock.c:110
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
SOCKET s
Definition: sock.c:106
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
Definition: dhcpd.h:245
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
u_int fd_count
Definition: winsock.h:67
char * buf
Definition: sock.c:109
int n_sent
Definition: sock.c:111
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define SOMAXCONN
Definition: winsock.h:399
#define closesocket
Definition: main.c:50
#define FALSE
Definition: types.h:117
#define FD_ISSET(fd, set)
Definition: winsock.h:100
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
static void server_start(server_params *par)
Definition: sock.c:460
SOCKET s
Definition: sock.c:155
smooth NULL
Definition: ftsmooth.c:513
test_params * general
Definition: sock.c:129
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
#define MAX_CLIENTS
Definition: sock.c:43
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
const char * inet_addr
Definition: sock.c:119
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:281
static void read_zero_bytes(SOCKET s)
Definition: sock.c:323
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
int buflen
Definition: sock.c:131
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
struct sockaddr_in peer
Definition: sock.c:108
int n_clients
Definition: sock.c:123
sock_info sock[MAX_CLIENTS]
Definition: sock.c:157
#define min(a, b)
Definition: monoChain.cc:55
static void server_stop(void)
Definition: sock.c:487
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
#define FD_CLR(fd, set)
Definition: winsock.h:74
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static HANDLE server_ready
Definition: sock.c:221
int n_chunks
Definition: sock.c:122
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
static DWORD WINAPI SelectCloseThread ( void param)
static

Definition at line 3634 of file sock.c.

Referenced by test_select(), and test_WSAPoll().

3635 {
3636  SOCKET s = *(SOCKET*)param;
3637  Sleep(500);
3638  closesocket(s);
3639  return 0;
3640 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define closesocket
Definition: main.c:50
GLdouble s
Definition: gl.h:2039
UINT_PTR SOCKET
Definition: winsock.h:47
static DWORD WINAPI SelectReadThread ( void param)
static

Definition at line 3608 of file sock.c.

Referenced by test_select().

3609 {
3610  select_thread_params *par = param;
3611  fd_set readfds;
3612  int ret;
3613  struct sockaddr_in addr;
3614  struct timeval select_timeout;
3615 
3616  FD_ZERO(&readfds);
3617  FD_SET(par->s, &readfds);
3618  select_timeout.tv_sec=5;
3619  select_timeout.tv_usec=0;
3620  addr.sin_family = AF_INET;
3621  addr.sin_addr.s_addr = inet_addr(SERVERIP);
3622  addr.sin_port = htons(SERVERPORT);
3623 
3624  do_bind(par->s, (struct sockaddr *)&addr, sizeof(addr));
3625  wsa_ok(listen(par->s, SOMAXCONN ), 0 ==, "SelectReadThread (%x): listen failed: %d\n");
3626 
3628  ret = select(par->s+1, &readfds, NULL, NULL, &select_timeout);
3629  par->ReadKilled = (ret == 1);
3630 
3631  return 0;
3632 }
Definition: winsock.h:66
#define inet_addr(cp)
Definition: inet.h:98
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
#define SOMAXCONN
Definition: winsock.h:399
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
smooth NULL
Definition: ftsmooth.c:513
GLfloat param
Definition: glext.h:5796
#define SERVERPORT
Definition: sock.c:56
int ret
GLenum const GLvoid * addr
Definition: glext.h:9621
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
static void do_bind(SOCKET s, struct sockaddr *addr, int addrlen)
Definition: sock.c:446
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
#define SERVERIP
Definition: sock.c:55
static HANDLE server_ready
Definition: sock.c:221
#define htons(x)
Definition: module.h:213
static void server_start ( server_params par)
static

Definition at line 460 of file sock.c.

Referenced by nfs41_lookup(), oob_server(), select_server(), and simple_server().

461 {
462  int i;
463  test_params *gen = par->general;
464  server_memory *mem = LocalAlloc ( LPTR, sizeof ( server_memory ) );
465 
466  TlsSetValue ( tls, mem );
467  mem->s = WSASocketA ( AF_INET, gen->sock_type, gen->sock_prot,
468  NULL, 0, par->sock_flags );
469  ok ( mem->s != INVALID_SOCKET, "Server: WSASocket failed\n" );
470 
471  mem->addr.sin_family = AF_INET;
472  mem->addr.sin_addr.s_addr = inet_addr ( gen->inet_addr );
473  mem->addr.sin_port = htons ( gen->inet_port );
474 
475  for (i = 0; i < MAX_CLIENTS; i++)
476  {
477  mem->sock[i].s = INVALID_SOCKET;
478  mem->sock[i].buf = LocalAlloc ( LPTR, gen->n_chunks * gen->chunk_size );
479  mem->sock[i].n_recvd = 0;
480  mem->sock[i].n_sent = 0;
481  }
482 
483  if ( gen->sock_type == SOCK_STREAM )
484  do_bind ( mem->s, (struct sockaddr*) &mem->addr, sizeof (mem->addr) );
485 }
#define inet_addr(cp)
Definition: inet.h:98
int n_recvd
Definition: sock.c:110
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1221
SOCKET s
Definition: sock.c:106
SOCKET WSAAPI WSASocketA(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOA lpProtocolInfo, IN GROUP g, IN DWORD dwFlags)
Definition: socklife.c:444
char * buf
Definition: sock.c:109
int n_sent
Definition: sock.c:111
GLenum GLclampf GLint i
Definition: glfuncs.h:14
int sock_prot
Definition: sock.c:118
SOCKET s
Definition: sock.c:155
smooth NULL
Definition: ftsmooth.c:513
test_params * general
Definition: sock.c:129
int sock_type
Definition: sock.c:117
#define MAX_CLIENTS
Definition: sock.c:43
#define INVALID_SOCKET
Definition: winsock.h:332
const char * inet_addr
Definition: sock.c:119
short inet_port
Definition: sock.c:120
static void do_bind(SOCKET s, struct sockaddr *addr, int addrlen)
Definition: sock.c:446
sock_info sock[MAX_CLIENTS]
Definition: sock.c:157
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
#define AF_INET
Definition: tcpip.h:117
#define LPTR
Definition: winbase.h:353
struct sockaddr_in addr
Definition: sock.c:156
#define ok(value,...)
Definition: CImage.cpp:33
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
static DWORD tls
Definition: sock.c:218
#define SOCK_STREAM
Definition: tcpip.h:118
#define htons(x)
Definition: module.h:213
int n_chunks
Definition: sock.c:122
DWORD sock_flags
Definition: sock.c:130
static void server_stop ( void  )
static

Definition at line 487 of file sock.c.

Referenced by oob_server(), select_server(), and simple_server().

488 {
489  int i;
491 
492  for (i = 0; i < MAX_CLIENTS; i++ )
493  {
494  LocalFree ( mem->sock[i].buf );
495  if ( mem->sock[i].s != INVALID_SOCKET )
496  closesocket ( mem->sock[i].s );
497  }
498  ok ( closesocket ( mem->s ) == 0, "closesocket failed\n" );
499  LocalFree ( mem );
501 }
SOCKET s
Definition: sock.c:106
char * buf
Definition: sock.c:109
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define closesocket
Definition: main.c:50
SOCKET s
Definition: sock.c:155
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:349
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
#define MAX_CLIENTS
Definition: sock.c:43
#define INVALID_SOCKET
Definition: winsock.h:332
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
sock_info sock[MAX_CLIENTS]
Definition: sock.c:157
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static int set_blocking ( SOCKET  s,
BOOL  blocking 
)
static
static void set_so_opentype ( BOOL  overlapped)
static

Definition at line 281 of file sock.c.

Referenced by oob_client(), oob_server(), select_server(), simple_client(), simple_mixed_client(), and simple_server().

282 {
283  int optval = !overlapped, newval, len = sizeof (int);
284 
286  (LPVOID) &optval, sizeof (optval) ) == 0,
287  "setting SO_OPENTYPE failed\n" );
289  (LPVOID) &newval, &len ) == 0,
290  "getting SO_OPENTYPE failed\n" );
291  ok ( optval == newval, "failed to set SO_OPENTYPE\n" );
292 }
#define SOL_SOCKET
Definition: winsock.h:398
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
#define INVALID_SOCKET
Definition: winsock.h:332
GLenum GLsizei len
Definition: glext.h:6722
INT WSAAPI getsockopt(IN SOCKET s, IN INT level, IN INT optname, OUT CHAR FAR *optval, IN OUT INT FAR *optlen)
Definition: sockctrl.c:271
#define SO_OPENTYPE
Definition: ws2_32.h:40
#define ok(value,...)
Definition: CImage.cpp:33
static int(WINAPI *pgetaddrinfo)(LPCSTR
static SOCKET setup_connector_socket ( struct sockaddr_in addr,
int  len,
BOOL  nonblock 
)
static

Definition at line 4218 of file sock.c.

Referenced by test_accept(), test_select(), and test_WSAPoll().

4219 {
4220  int ret;
4221  SOCKET connector;
4222 
4223  connector = socket(AF_INET, SOCK_STREAM, 0);
4224  ok(connector != INVALID_SOCKET, "failed to create connector socket %d\n", WSAGetLastError());
4225 
4226  if (nonblock)
4227  set_blocking(connector, !nonblock);
4228 
4229  ret = connect(connector, (struct sockaddr *)addr, len);
4230  if (!nonblock)
4231  ok(!ret, "connecting to accepting socket failed %d\n", WSAGetLastError());
4232  else if (ret == SOCKET_ERROR)
4233  {
4235  ok(error == WSAEWOULDBLOCK || error == WSAEINPROGRESS,
4236  "expected 10035 or 10036, got %d\n", error);
4237  }
4238 
4239  return connector;
4240 }
#define SOCKET_ERROR
Definition: winsock.h:333
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
#define WSAEINPROGRESS
Definition: winerror.h:1949
DWORD DWORD
Definition: winlogon.h:75
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
static int nonblock(int fd, int isnonblock)
Definition: adnsresfilter.c:86
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define AF_INET
Definition: tcpip.h:117
#define ok(value,...)
Definition: CImage.cpp:33
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCK_STREAM
Definition: tcpip.h:118
static SOCKET setup_iocp_src ( struct sockaddr_in bindAddress)
static

Definition at line 9187 of file sock.c.

Referenced by test_completion_port().

9188 {
9190  int iret, socklen;
9191 
9192  src = socket(AF_INET, SOCK_STREAM, 0);
9193  if (src == INVALID_SOCKET)
9194  {
9195  skip("could not create listener socket, error %d\n", WSAGetLastError());
9196  goto end;
9197  }
9198 
9199  memset(bindAddress, 0, sizeof(*bindAddress));
9200  bindAddress->sin_family = AF_INET;
9201  bindAddress->sin_addr.s_addr = inet_addr("127.0.0.1");
9202  iret = bind(src, (struct sockaddr*)bindAddress, sizeof(*bindAddress));
9203  if (iret != 0)
9204  {
9205  skip("failed to bind, error %d\n", WSAGetLastError());
9206  goto end;
9207  }
9208 
9209  socklen = sizeof(*bindAddress);
9210  iret = getsockname(src, (struct sockaddr*)bindAddress, &socklen);
9211  if (iret != 0) {
9212  skip("failed to lookup bind address, error %d\n", WSAGetLastError());
9213  goto end;
9214  }
9215 
9216  if (set_blocking(src, FALSE))
9217  {
9218  skip("couldn't make socket non-blocking, error %d\n", WSAGetLastError());
9219  goto end;
9220  }
9221 
9222  iret = listen(src, 5);
9223  if (iret != 0)
9224  {
9225  skip("listening failed, errno = %d\n", WSAGetLastError());
9226  goto end;
9227  }
9228 
9229  ret = src;
9230 end:
9231  if (src != ret && ret == INVALID_SOCKET)
9232  closesocket(src);
9233  return ret;
9234 }
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define inet_addr(cp)
Definition: inet.h:98
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
GLuint GLuint end
Definition: gl.h:1545
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define closesocket
Definition: main.c:50
#define FALSE
Definition: types.h:117
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
int ret
struct in_addr sin_addr
Definition: winsock.h:512
#define skip(...)
Definition: CString.cpp:57
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCK_STREAM
Definition: tcpip.h:118
#define memset(x, y, z)
Definition: compat.h:39
short sin_family
Definition: winsock.h:510
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213
static SOCKET setup_server_socket ( struct sockaddr_in addr,
int len 
)
static

Definition at line 4172 of file sock.c.

Referenced by test_accept(), test_select(), and test_WSAPoll().

4173 {
4174  int ret, val;
4176 
4177  server_socket = socket(AF_INET, SOCK_STREAM, 0);
4178  if (server_socket == INVALID_SOCKET)
4179  {
4180  trace("error creating server socket: %d\n", WSAGetLastError());
4181  return INVALID_SOCKET;
4182  }
4183 
4184  val = 1;
4185  ret = setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
4186  if (ret)
4187  {
4188  trace("error setting SO_REUSEADDR: %d\n", WSAGetLastError());
4189  closesocket(server_socket);
4190  return INVALID_SOCKET;
4191  }
4192 
4193  ret = bind(server_socket, (struct sockaddr *)addr, *len);
4194  if (ret)
4195  {
4196  trace("error binding server socket: %d\n", WSAGetLastError());
4197  }
4198 
4199  ret = getsockname(server_socket, (struct sockaddr *)addr, len);
4200  if (ret)
4201  {
4202  skip("failed to lookup bind address: %d\n", WSAGetLastError());
4203  closesocket(server_socket);
4204  return INVALID_SOCKET;
4205  }
4206 
4207  ret = listen(server_socket, 5);
4208  if (ret)
4209  {
4210  trace("error making server socket listen: %d\n", WSAGetLastError());
4211  closesocket(server_socket);
4212  return INVALID_SOCKET;
4213  }
4214 
4215  return server_socket;
4216 }
#define trace(...)
Definition: kmt_test.h:172
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
#define SOL_SOCKET
Definition: winsock.h:398
static int server_socket
Definition: http.c:2083
#define closesocket
Definition: main.c:50
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
#define SO_REUSEADDR
Definition: winsock.h:180
GLuint GLfloat * val
Definition: glext.h:7180
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define skip(...)
Definition: CString.cpp:57
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCK_STREAM
Definition: tcpip.h:118
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213
static VOID WINAPI simple_client ( client_params par)
static

Definition at line 810 of file sock.c.

811 {
812  test_params *gen = par->general;
814  int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
815 
816  id = GetCurrentThreadId();
817  trace ( "simple_client (%x): starting\n", id );
818  /* wait here because we want to call set_so_opentype before creating a socket */
820  trace ( "simple_client (%x): server ready\n", id );
821 
823  set_so_opentype ( FALSE ); /* non-overlapped */
824  client_start ( par );
825  mem = TlsGetValue ( tls );
826 
827  /* Connect */
828  wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
829  0 ==, "simple_client (%x): connect error: %d\n" );
830  ok ( set_blocking ( mem->s, TRUE ) == 0,
831  "simple_client (%x): failed to set blocking mode\n", id );
832  trace ( "simple_client (%x) connected\n", id );
833 
834  /* send data to server */
835  n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, 0, par->buflen );
836  ok ( n_sent == n_expected,
837  "simple_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
838 
839  /* shutdown send direction */
840  wsa_ok ( shutdown ( mem->s, SD_SEND ), 0 ==, "simple_client (%x): shutdown failed: %d\n" );
841 
842  /* Receive data echoed back & check it */
843  n_recvd = do_synchronous_recv ( mem->s, mem->recv_buf, n_expected, 0, par->buflen );
844  ok ( n_recvd == n_expected,
845  "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
846 
847  /* check data */
848  pos = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
849  ok ( pos == -1, "simple_client (%x): test pattern error: %d\n", id, pos);
850 
851  /* cleanup */
852  read_zero_bytes ( mem->s );
853  trace ( "simple_client (%x) exiting\n", id );
854  client_stop ();
855 }
#define trace(...)
Definition: kmt_test.h:172
#define TRUE
Definition: types.h:120
test_params * general
Definition: sock.c:137
char * recv_buf
Definition: sock.c:166
static void check_so_opentype(void)
Definition: sock.c:375
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
struct sockaddr_in addr
Definition: sock.c:164
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
SOCKET s
Definition: sock.c:163
int buflen
Definition: sock.c:139
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:281
static void read_zero_bytes(SOCKET s)
Definition: sock.c:323
static void client_start(client_params *par)
Definition: sock.c:505
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
#define SD_SEND
Definition: winsock.h:55
static int do_synchronous_recv(SOCKET s, char *buf, int buflen, int flags, int recvlen)
Definition: sock.c:345
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
char * send_buf
Definition: sock.c:165
GLenum GLuint id
Definition: glext.h:5579
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static int do_synchronous_send(SOCKET s, char *buf, int buflen, int flags, int sendlen)
Definition: sock.c:332
static HANDLE server_ready
Definition: sock.c:221
#define INFINITE
Definition: serial.h:102
int n_chunks
Definition: sock.c:122
static void client_stop(void)
Definition: sock.c:532
static VOID WINAPI simple_mixed_client ( client_params par)
static

Definition at line 913 of file sock.c.

914 {
915  test_params *gen = par->general;
917  int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
918  int fromLen = sizeof(mem->addr);
919  struct sockaddr test;
920 
921  id = GetCurrentThreadId();
922  trace ( "simple_client (%x): starting\n", id );
923  /* wait here because we want to call set_so_opentype before creating a socket */
925  trace ( "simple_client (%x): server ready\n", id );
926 
928  set_so_opentype ( FALSE ); /* non-overlapped */
929  client_start ( par );
930  mem = TlsGetValue ( tls );
931 
932  /* Connect */
933  wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
934  0 ==, "simple_client (%x): connect error: %d\n" );
935  ok ( set_blocking ( mem->s, TRUE ) == 0,
936  "simple_client (%x): failed to set blocking mode\n", id );
937  trace ( "simple_client (%x) connected\n", id );
938 
939  /* send data to server */
940  n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, 0, par->buflen );
941  ok ( n_sent == n_expected,
942  "simple_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
943 
944  /* shutdown send direction */
945  wsa_ok ( shutdown ( mem->s, SD_SEND ), 0 ==, "simple_client (%x): shutdown failed: %d\n" );
946 
947  /* this shouldn't change, since lpFrom, is not updated on
948  connection oriented sockets - exposed by bug 11640
949  */
950  ((struct sockaddr_in*)&test)->sin_addr.s_addr = inet_addr("0.0.0.0");
951 
952  /* Receive data echoed back & check it */
953  n_recvd = do_synchronous_recvfrom ( mem->s,
954  mem->recv_buf,
955  n_expected,
956  0,
957  (struct sockaddr *)&test,
958  &fromLen,
959  par->buflen );
960  ok ( n_recvd == n_expected,
961  "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
962 
963  /* check that lpFrom was not updated */
964  ok(0 ==
965  strcmp(
966  inet_ntoa(((struct sockaddr_in*)&test)->sin_addr),
967  "0.0.0.0"), "lpFrom shouldn't be updated on connection oriented sockets\n");
968 
969  /* check data */
970  pos = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
971  ok ( pos == -1, "simple_client (%x): test pattern error: %d\n", id, pos);
972 
973  /* cleanup */
974  read_zero_bytes ( mem->s );
975  trace ( "simple_client (%x) exiting\n", id );
976  client_stop ();
977 }
#define trace(...)
Definition: kmt_test.h:172
#define TRUE
Definition: types.h:120
test_params * general
Definition: sock.c:137
static int do_synchronous_recvfrom(SOCKET s, char *buf, int buflen, int flags, struct sockaddr *from, int *fromlen, int recvlen)
Definition: sock.c:358
char * recv_buf
Definition: sock.c:166
static void check_so_opentype(void)
Definition: sock.c:375
#define inet_addr(cp)
Definition: inet.h:98
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
#define test
Definition: rosglue.h:37
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
#define inet_ntoa(addr)
Definition: inet.h:100
struct sockaddr_in addr
Definition: sock.c:164
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
SOCKET s
Definition: sock.c:163
int buflen
Definition: sock.c:139
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:281
static void read_zero_bytes(SOCKET s)
Definition: sock.c:323
static void client_start(client_params *par)
Definition: sock.c:505
struct in_addr sin_addr
Definition: winsock.h:512
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
#define SD_SEND
Definition: winsock.h:55
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
char * send_buf
Definition: sock.c:165
GLenum GLuint id
Definition: glext.h:5579
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static int do_synchronous_send(SOCKET s, char *buf, int buflen, int flags, int sendlen)
Definition: sock.c:332
static HANDLE server_ready
Definition: sock.c:221
#define INFINITE
Definition: serial.h:102
int n_chunks
Definition: sock.c:122
static void client_stop(void)
Definition: sock.c:532
static VOID WINAPI simple_server ( server_params par)
static

Definition at line 546 of file sock.c.

547 {
548  test_params *gen = par->general;
550  int pos, n_recvd, n_sent, n_expected = gen->n_chunks * gen->chunk_size, tmp, i,
551  id = GetCurrentThreadId();
552 
553  trace ( "simple_server (%x) starting\n", id );
554 
555  set_so_opentype ( FALSE ); /* non-overlapped */
556  server_start ( par );
557  mem = TlsGetValue ( tls );
558 
559  wsa_ok ( set_blocking ( mem->s, TRUE ), 0 ==, "simple_server (%x): failed to set blocking mode: %d\n");
560  wsa_ok ( listen ( mem->s, SOMAXCONN ), 0 ==, "simple_server (%x): listen failed: %d\n");
561 
562  trace ( "simple_server (%x) ready\n", id );
563  SetEvent ( server_ready ); /* notify clients */
564 
565  for ( i = 0; i < min ( gen->n_clients, MAX_CLIENTS ); i++ )
566  {
567  trace ( "simple_server (%x): waiting for client\n", id );
568 
569  /* accept a single connection */
570  tmp = sizeof ( mem->sock[0].peer );
571  mem->sock[0].s = accept ( mem->s, (struct sockaddr*) &mem->sock[0].peer, &tmp );
572  wsa_ok ( mem->sock[0].s, INVALID_SOCKET !=, "simple_server (%x): accept failed: %d\n" );
573 
574  ok ( mem->sock[0].peer.sin_addr.s_addr == inet_addr ( gen->inet_addr ),
575  "simple_server (%x): strange peer address\n", id );
576 
577  /* Receive data & check it */
578  n_recvd = do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
579  ok ( n_recvd == n_expected,
580  "simple_server (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
581  pos = test_buffer ( mem->sock[0].buf, gen->chunk_size, gen->n_chunks );
582  ok ( pos == -1, "simple_server (%x): test pattern error: %d\n", id, pos);
583 
584  /* Echo data back */
585  n_sent = do_synchronous_send ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
586  ok ( n_sent == n_expected,
587  "simple_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
588 
589  /* cleanup */
590  read_zero_bytes ( mem->sock[0].s );
591  wsa_ok ( closesocket ( mem->sock[0].s ), 0 ==, "simple_server (%x): closesocket error: %d\n" );
592  mem->sock[0].s = INVALID_SOCKET;
593  }
594 
595  trace ( "simple_server (%x) exiting\n", id );
596  server_stop ();
597 }
#define trace(...)
Definition: kmt_test.h:172
#define TRUE
Definition: types.h:120
#define inet_addr(cp)
Definition: inet.h:98
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:294
SOCKET s
Definition: sock.c:106
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
char * buf
Definition: sock.c:109
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define SOMAXCONN
Definition: winsock.h:399
#define closesocket
Definition: main.c:50
#define FALSE
Definition: types.h:117
static void server_start(server_params *par)
Definition: sock.c:460
SOCKET s
Definition: sock.c:155
test_params * general
Definition: sock.c:129
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:443
#define MAX_CLIENTS
Definition: sock.c:43
#define INVALID_SOCKET
Definition: winsock.h:332
const char * inet_addr
Definition: sock.c:119
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:281
static void read_zero_bytes(SOCKET s)
Definition: sock.c:323
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
int buflen
Definition: sock.c:131
static int test_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:307
#define wsa_ok(op, cond, msg)
Definition: sock.c:58
struct sockaddr_in peer
Definition: sock.c:108
int n_clients
Definition: sock.c:123
sock_info sock[MAX_CLIENTS]
Definition: sock.c:157
static int do_synchronous_recv(SOCKET s, char *buf, int buflen, int flags, int recvlen)
Definition: sock.c:345
#define min(a, b)
Definition: monoChain.cc:55
static void server_stop(void)
Definition: sock.c:487
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1185
Definition: mem.c:156
int chunk_size
Definition: sock.c:121
#define ok(value,...)
Definition: CImage.cpp:33
static DWORD tls
Definition: sock.c:218
static int do_synchronous_send(SOCKET s, char *buf, int buflen, int flags, int sendlen)
Definition: sock.c:332
static HANDLE server_ready
Definition: sock.c:221
int n_chunks
Definition: sock.c:122
START_TEST ( sock  )

Definition at line 10499 of file sock.c.

10500 {
10501  int i;
10502 
10503 /* Leave these tests at the beginning. They depend on WSAStartup not having been
10504  * called, which is done by Init() below. */
10507 
10508  Init();
10509 
10510  test_inet_ntoa();
10511  test_inet_pton();
10514  test_ip_pktinfo();
10516 
10517  for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
10518  {
10519  trace ( " **** STARTING TEST %d ****\n", i );
10520  do_test ( &tests[i] );
10521  trace ( " **** TEST %d COMPLETE ****\n", i );
10522  }
10523 
10524  test_UDP();
10525 
10527  test_WSASocket();
10530 
10533 
10536 
10537  test_errors();
10538  test_listen();
10539  test_select();
10540  test_accept();
10541  test_getpeername();
10542  test_getsockname();
10543  test_inet_addr();
10545  test_ioctlsocket();
10546  test_dns();
10549  test_gethostname();
10550 
10551  test_WSASendMsg();
10552  test_WSASendTo();
10553  test_WSARecv();
10554  test_WSAPoll();
10555 
10556  test_events(0);
10557  test_events(1);
10558 
10559  test_ipv6only();
10562  test_getaddrinfo();
10563  test_AcceptEx();
10564  test_ConnectEx();
10566 
10569 
10573 
10576 
10579 
10580  /* this is an io heavy test, do it at the end so the kernel doesn't start dropping packets */
10581  test_send();
10583 
10584  Exit();
10585 }
static void test_WSARecv(void)
Definition: sock.c:6713
#define trace(...)
Definition: kmt_test.h:172
static void test_WithWSAStartup(void)
Definition: sock.c:1124
static void test_WSAAddressToStringA(void)
Definition: sock.c:2972
static void test_TransmitFile(void)
Definition: sock.c:8418
static void test_gethostbyname(void)
Definition: sock.c:4670
static void test_addr_to_print(void)
Definition: sock.c:4864
static void test_WSAAsyncGetServByName(void)
Definition: sock.c:9153
static void test_listen(void)
Definition: sock.c:3679
static void test_set_getsockopt(void)
Definition: sock.c:1342
static void test_getservbyname(void)
Definition: sock.c:2324
static void test_WSAAsyncGetServByPort(void)
Definition: sock.c:9123
static void test_address_list_query(void)
Definition: sock.c:10058
static void test_ip_pktinfo(void)
Definition: sock.c:1939
static void test_getaddrinfo(void)
Definition: sock.c:7385
static void test_gethostname(void)
Definition: sock.c:4823
static void test_WSAAddressToStringW(void)
Definition: sock.c:3155
static void test_DisconnectEx(void)
Definition: sock.c:8296
static void test_inet_addr(void)
Definition: sock.c:4856
static void test_WSAStringToAddressA(void)
Definition: sock.c:3344
static test_setup tests[]
Definition: sock.c:2126
static void test_inet_pton(void)
Definition: sock.c:4995
static void test_extendedSocketOptions(void)
Definition: sock.c:4405
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static void test_so_reuseaddr(void)
Definition: sock.c:1860
static void test_WSADuplicateSocket(void)
Definition: sock.c:2731
static void test_WSASendTo(void)
Definition: sock.c:6649
static void test_UDP(void)
Definition: sock.c:2235
static void test_completion_port(void)
Definition: sock.c:9236
static void test_dns(void)
Definition: sock.c:4614
static void test_WSAEnumNameSpaceProvidersW(void)
Definition: sock.c:10412
static void test_select(void)
Definition: sock.c:3766
static void Init(void)
Definition: sock.c:1227
static void test_events(int useMessages)
Definition: sock.c:5739
static void test_ipv6only(void)
Definition: sock.c:6315
static void test_synchronous_WSAIoctl(void)
Definition: sock.c:9040
static void Exit(void)
Definition: sock.c:1263
static void test_WSAStringToAddressW(void)
Definition: sock.c:3468
static void test_gethostbyname_hack(void)
Definition: sock.c:4766
static void test_ConnectEx(void)
Definition: sock.c:7571
static void test_WSASocket(void)
Definition: sock.c:2345
static void test_getpeername(void)
Definition: sock.c:8651
static void test_WSALookupService(void)
Definition: sock.c:10166
static void test_WSAPoll(void)
Definition: sock.c:6902
static void test_inet_ntoa(void)
Definition: sock.c:10138
static void test_getsockname(void)
Definition: sock.c:4522
static void test_WSASendMsg(void)
Definition: sock.c:6464
static void test_AcceptEx(void)
Definition: sock.c:7787
static void test_WSAEnumNetworkEvents(void)
Definition: sock.c:2892
static void do_test(test_setup *test)
Definition: sock.c:1295
static void test_WSAEnumNameSpaceProvidersA(void)
Definition: sock.c:10327
static void test_sioRoutingInterfaceQuery(void)
Definition: sock.c:8743
static void test_sioAddressListChange(void)
Definition: sock.c:8804
static void test_GetAddrInfoW(void)
Definition: sock.c:7112
static void test_send(void)
Definition: sock.c:5317
static void test_accept(void)
Definition: sock.c:4242
static void test_WithoutWSAStartup(void)
Definition: sock.c:1109
static void test_errors(void)
Definition: sock.c:3642
static void test_ioctlsocket(void)
Definition: sock.c:5140
static void StartClients ( LPTHREAD_START_ROUTINE  routine,
test_params general,
client_params par 
)
static

Definition at line 1280 of file sock.c.

Referenced by do_test().

1282 {
1283  int i;
1284  par->general = general;
1285  for ( i = 1; i <= min ( general->n_clients, MAX_CLIENTS ); i++ )
1286  {
1287  client_id = i - 1;
1288  thread[i] = CreateThread ( NULL, 0, routine, par, 0, &thread_id[i] );
1289  ok ( thread[i] != NULL, "Failed to create client thread\n" );
1290  /* Make sure the client is up and running */
1292  };
1293 }
test_params * general
Definition: sock.c:137
static HANDLE thread[1+MAX_CLIENTS]
Definition: sock.c:219
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static int client_id
Definition: sock.c:223
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
smooth NULL
Definition: ftsmooth.c:513
#define MAX_CLIENTS
Definition: sock.c:43
static DWORD thread_id[1+MAX_CLIENTS]
Definition: sock.c:220
static HANDLE client_ready[MAX_CLIENTS]
Definition: sock.c:222
int jpeg_marker_parser_method routine
Definition: jpeglib.h:1089
int n_clients
Definition: sock.c:123
#define min(a, b)
Definition: monoChain.cc:55
#define ok(value,...)
Definition: CImage.cpp:33
#define INFINITE
Definition: serial.h:102
static void StartServer ( LPTHREAD_START_ROUTINE  routine,
test_params general,
server_params par 
)
static

Definition at line 1272 of file sock.c.

Referenced by do_test().

1274 {
1275  par->general = general;
1276  thread[0] = CreateThread ( NULL, 0, routine, par, 0, &thread_id[0] );
1277  ok ( thread[0] != NULL, "Failed to create server thread\n" );
1278 }
static HANDLE thread[1+MAX_CLIENTS]
Definition: sock.c:219
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
smooth NULL
Definition: ftsmooth.c:513
test_params * general
Definition: sock.c:129
static DWORD thread_id[1+MAX_CLIENTS]
Definition: sock.c:220
int jpeg_marker_parser_method routine
Definition: jpeglib.h:1089
#define ok(value,...)
Definition: CImage.cpp:33
static int tcp_socketpair ( SOCKET src,
SOCKET dst 
)
static

Definition at line 230 of file sock.c.

Referenced by test_completion_port(), test_ioctlsocket(), test_select(), test_send(), test_WithWSAStartup(), test_WSAEnumNetworkEvents(), test_WSAPoll(), and test_WSARecv().

231 {
233  struct sockaddr_in addr;
234  int len;
235  int ret;
236 
237  *src = INVALID_SOCKET;
238  *dst = INVALID_SOCKET;
239 
241  if (*src == INVALID_SOCKET)
242  goto end;
243 
245  if (server == INVALID_SOCKET)
246  goto end;
247 
248  memset(&addr, 0, sizeof(addr));
249  addr.sin_family = AF_INET;
250  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
251  ret = bind(server, (struct sockaddr*)&addr, sizeof(addr));
252  if (ret != 0)
253  goto end;
254 
255  len = sizeof(addr);
256  ret = getsockname(server, (struct sockaddr*)&addr, &len);
257  if (ret != 0)
258  goto end;
259 
260  ret = listen(server, 1);
261  if (ret != 0)
262  goto end;
263 
264  ret = connect(*src, (struct sockaddr*)&addr, sizeof(addr));
265  if (ret != 0)
266  goto end;
267 
268  len = sizeof(addr);
269  *dst = accept(server, (struct sockaddr*)&addr, &len);
270 
271 end:
272  if (server != INVALID_SOCKET)
273  closesocket(server);
274  if (*src != INVALID_SOCKET && *dst != INVALID_SOCKET)
275  return 0;
276  closesocket(*src);
277  closesocket(*dst);
278  return -1;
279 }
static rfbScreenInfoPtr server
Definition: vnc.c:74
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define inet_addr(cp)
Definition: inet.h:98
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
GLuint GLuint end
Definition: gl.h:1545
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define closesocket
Definition: main.c:50
#define INVALID_SOCKET
Definition: winsock.h:332
int ret
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCK_STREAM
Definition: tcpip.h:118
#define memset(x, y, z)
Definition: compat.h:39
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213
static void test_accept ( void  )
static

Definition at line 4242 of file sock.c.

Referenced by START_TEST().

4243 {
4244  int ret;
4246  struct sockaddr_in address;
4247  SOCKADDR_STORAGE ss, ss_empty;
4248  int socklen;
4249  select_thread_params thread_params;
4250  HANDLE thread_handle = NULL;
4251  DWORD id;
4252 
4253  memset(&address, 0, sizeof(address));
4254  address.sin_addr.s_addr = inet_addr("127.0.0.1");
4255  address.sin_family = AF_INET;
4256 
4257  socklen = sizeof(address);
4258  server_socket = setup_server_socket(&address, &socklen);
4259  if (server_socket == INVALID_SOCKET)
4260  {
4261  trace("error creating server socket: %d\n", WSAGetLastError());
4262  return;
4263  }
4264 
4265  connector = setup_connector_socket(&address, socklen, FALSE);
4266  if (connector == INVALID_SOCKET) goto done;
4267 
4268  trace("Blocking accept next\n");
4269 
4270  accepted = WSAAccept(server_socket, NULL, NULL, AlwaysDeferConditionFunc, 0);
4271  ok(accepted == INVALID_SOCKET && WSAGetLastError() == WSATRY_AGAIN, "Failed to defer connection, %d\n", WSAGetLastError());
4272 
4273  accepted = accept(server_socket, NULL, 0);
4274  ok(accepted != INVALID_SOCKET, "Failed to accept deferred connection, error %d\n", WSAGetLastError());
4275 
4278  {
4279  trace("error creating event: %d\n", GetLastError());
4280  goto done;
4281  }
4282 
4283  thread_params.s = server_socket;
4284  thread_params.ReadKilled = FALSE;
4285  thread_handle = CreateThread(NULL, 0, AcceptKillThread, &thread_params, 0, &id);
4286  if (thread_handle == NULL)
4287  {
4288  trace("error creating thread: %d\n", GetLastError());
4289  goto done;
4290  }
4291 
4293  Sleep(200);
4294  ret = closesocket(server_socket);
4295  if (ret != 0)
4296  {
4297  trace("closesocket failed: %d\n", WSAGetLastError());
4298  goto done;
4299  }
4300 
4301  WaitForSingleObject(thread_handle, 1000);
4302  ok(thread_params.ReadKilled || broken(!thread_params.ReadKilled) /* Win98/ME, after accept */,
4303  "closesocket did not wakeup accept\n");
4304 
4305  closesocket(accepted);
4306  closesocket(connector);
4307  accepted = connector = INVALID_SOCKET;
4308 
4309  socklen = sizeof(address);
4310  server_socket = setup_server_socket(&address, &socklen);
4311  if (server_socket == INVALID_SOCKET) goto done;
4312 
4313  connector = setup_connector_socket(&address, socklen, FALSE);
4314  if (connector == INVALID_SOCKET) goto done;
4315 
4316  socklen = 0;
4317  accepted = WSAAccept(server_socket, (struct sockaddr *)&ss, &socklen, NULL, 0);
4318  ok(accepted == INVALID_SOCKET && WSAGetLastError() == WSAEFAULT, "got %d\n", WSAGetLastError());
4319  ok(!socklen, "got %d\n", socklen);
4320  closesocket(connector);
4321  connector = INVALID_SOCKET;
4322 
4323  socklen = sizeof(address);
4324  connector = setup_connector_socket(&address, socklen, FALSE);
4325  if (connector == INVALID_SOCKET) goto done;
4326 
4327  accepted = WSAAccept(server_socket, NULL, NULL, NULL, 0);
4328  ok(accepted != INVALID_SOCKET, "Failed to accept connection, %d\n", WSAGetLastError());
4329  closesocket(accepted);
4330  closesocket(connector);
4331  accepted = connector = INVALID_SOCKET;
4332 
4333  socklen = sizeof(address);
4334  connector = setup_connector_socket(&address, socklen, FALSE);
4335  if (connector == INVALID_SOCKET) goto done;
4336 
4337  socklen = sizeof(ss);
4338  memset(&ss, 0, sizeof(ss));
4339  accepted = WSAAccept(server_socket, (struct sockaddr *)&ss, &socklen, NULL, 0);
4340  ok(accepted != INVALID_SOCKET, "Failed to accept connection, %d\n", WSAGetLastError());
4341