ReactOS 0.4.15-dev-6056-gb29b268
sock.c File Reference
#include <ntstatus.h>
#include <winsock2.h>
#include <windows.h>
#include <winternl.h>
#include <ws2tcpip.h>
#include <wsipx.h>
#include <wsnwlink.h>
#include <mswsock.h>
#include <mstcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
#include "wine/test.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
 
struct  write_watch_thread_args
 
struct  wsa_async_select_info
 
struct  wsa_recv_info
 

Macros

#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 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 int tcp_socketpair_ovl (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 DWORD CALLBACK write_watch_thread (void *arg)
 
static void test_write_watch (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_GetAddrInfoExW (void)
 
static void verify_ipv6_addrinfo (ADDRINFOA *result, const char *expectedIp)
 
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)
 
static void sync_read (SOCKET src, SOCKET dst)
 
static void iocp_async_read (SOCKET src, SOCKET dst)
 
static void iocp_async_read_closesocket (SOCKET src, int how_to_close)
 
static void iocp_async_closesocket (SOCKET src)
 
static DWORD WINAPI wsa_async_select_thread (void *param)
 
static DWORD WINAPI wsa_recv_thread (void *param)
 
static void iocp_async_read_thread_closesocket (SOCKET src)
 
static void iocp_async_read_thread (SOCKET src, SOCKET dst)
 
static void test_iocp (void)
 
 START_TEST (sock)
 

Variables

static LPCSTR
 
static LPCWSTR
 
static const ADDRINFOW PADDRINFOW *static const WCHARservname
 
namespace GUIDnamespace_id
 
namespace GUID const ADDRINFOEXW * hints
 
namespace GUID const ADDRINFOEXW ADDRINFOEXW ** result
 
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timevaltimeout
 
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPEDoverlapped
 
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE completion_routine
 
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLEhandle
 
static LPVOID
 
static LPSTR
 
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

◆ BIND_SLEEP

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

Definition at line 48 of file sock.c.

◆ BIND_TRIES

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

Definition at line 49 of file sock.c.

◆ compare_file

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

Definition at line 8828 of file sock.c.

◆ FD_SET_ALL

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

Definition at line 3779 of file sock.c.

◆ FD_ZERO_ALL

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

Definition at line 3778 of file sock.c.

◆ FIRST_CHAR

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

Definition at line 47 of file sock.c.

◆ IP_PKTINFO_LEN

Definition at line 2001 of file sock.c.

◆ make_keepalive

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

Definition at line 68 of file sock.c.

◆ MAX_CLIENTS

#define MAX_CLIENTS   4 /* Max number of clients */

Definition at line 46 of file sock.c.

◆ NUM_QUERIES

#define NUM_QUERIES   250 /* Number of getservbyname queries per thread */

Definition at line 55 of file sock.c.

◆ NUM_THREADS

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

Definition at line 54 of file sock.c.

◆ NUM_UDP_PEERS

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

Definition at line 52 of file sock.c.

◆ ok_event_seq

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

Definition at line 5774 of file sock.c.

◆ POLL_CLEAR

#define POLL_CLEAR ( )    ix = 0

Definition at line 7111 of file sock.c.

◆ POLL_ISSET

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

Definition at line 7113 of file sock.c.

◆ POLL_SET

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

Definition at line 7112 of file sock.c.

◆ SERVERIP

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

Definition at line 57 of file sock.c.

◆ SERVERPORT

#define SERVERPORT   9374 /* Port number to bind to */

Definition at line 58 of file sock.c.

◆ SOCKTIMEOUT1

#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 1405 of file sock.c.

◆ SOCKTIMEOUT2

#define SOCKTIMEOUT2   997000 /* 997 seconds */

Definition at line 1406 of file sock.c.

◆ STD_STREAM_SOCKET

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

Definition at line 2184 of file sock.c.

◆ TEST_TIMEOUT

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

Definition at line 50 of file sock.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 30 of file sock.c.

◆ WM_ASYNCCOMPLETE

#define WM_ASYNCCOMPLETE   (WM_USER + 100)

Definition at line 9494 of file sock.c.

◆ WM_SOCKET

#define WM_SOCKET   (WM_USER+100)

Definition at line 5504 of file sock.c.

◆ WSA_CMSG_ALIGN

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

Definition at line 44 of file sock.c.

◆ wsa_ok

#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);
#define msg(x)
Definition: auth_time.c:54
UINT op
Definition: effect.c:236
#define err(...)
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112

Definition at line 60 of file sock.c.

Typedef Documentation

◆ async_message

◆ client_memory

◆ client_params

◆ select_thread_params

◆ server_memory

◆ server_params

◆ sock_info

◆ test_params

◆ test_setup

◆ thread_info

Function Documentation

◆ AcceptKillThread()

static DWORD WINAPI AcceptKillThread ( void param)
static

Definition at line 4158 of file sock.c.

4161{
4163 struct sockaddr_in address;
4164 int len = sizeof(address);
4165 SOCKET client_socket;
4166
4168 client_socket = accept(par->s, (struct sockaddr*) &address, &len);
4169 if (client_socket != INVALID_SOCKET)
4170 closesocket(client_socket);
4171 par->ReadKilled = (client_socket == INVALID_SOCKET);
GLuint address
Definition: glext.h:9393
GLfloat param
Definition: glext.h:5796
GLenum GLsizei len
Definition: glext.h:6722
#define closesocket
Definition: ncftp.h:477
static HANDLE server_ready
Definition: sock.c:232
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47

◆ AlwaysDeferConditionFunc()

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 4174 of file sock.c.

4179{

◆ check_so_opentype()

static void check_so_opentype ( void  )
static

Definition at line 436 of file sock.c.

438{
439 int tmp = 1, len;
440 len = sizeof (tmp);
442 ok ( tmp == 0, "check_so_opentype: wrong startup value of SO_OPENTYPE: %d\n", tmp );
#define ok(value,...)
Definition: atltest.h:57
#define SO_OPENTYPE
Definition: ws2_32.h:40
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 SOL_SOCKET
Definition: winsock.h:398

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

◆ client_start()

static void client_start ( client_params par)
static

Definition at line 566 of file sock.c.

568{
569 test_params *gen = par->general;
571
572 TlsSetValue ( tls, mem );
573
575
576 mem->s = WSASocketA ( AF_INET, gen->sock_type, gen->sock_prot,
577 NULL, 0, par->sock_flags );
578
579 mem->addr.sin_family = AF_INET;
580 mem->addr.sin_addr.s_addr = inet_addr ( gen->inet_addr );
581 mem->addr.sin_port = htons ( gen->inet_port );
582
583 ok ( mem->s != INVALID_SOCKET, "Client: WSASocket failed\n" );
584
585 mem->send_buf = LocalAlloc ( LPTR, 2 * gen->n_chunks * gen->chunk_size );
586 mem->recv_buf = mem->send_buf + gen->n_chunks * gen->chunk_size;
587 fill_buffer ( mem->send_buf, gen->chunk_size, gen->n_chunks );
588
590 /* Wait for the other clients to come up */
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1276
#define AF_INET
Definition: tcpip.h:117
#define INFINITE
Definition: serial.h:102
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
#define inet_addr(cp)
Definition: inet.h:98
#define htons(x)
Definition: module.h:215
#define min(a, b)
Definition: monoChain.cc:55
#define MAX_CLIENTS
Definition: sock.c:46
static HANDLE client_ready[MAX_CLIENTS]
Definition: sock.c:233
static void fill_buffer(char *buf, int chunk_size, int n_chunks)
Definition: sock.c:361
static int client_id
Definition: sock.c:234
static DWORD tls
Definition: sock.c:229
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
DWORD sock_flags
Definition: sock.c:149
test_params * general
Definition: sock.c:148
Definition: mem.c:156
int sock_type
Definition: sock.c:128
const char * inet_addr
Definition: sock.c:130
int sock_prot
Definition: sock.c:129
int n_chunks
Definition: sock.c:133
short inet_port
Definition: sock.c:131
int n_clients
Definition: sock.c:134
int chunk_size
Definition: sock.c:132
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
#define LPTR
Definition: winbase.h:381

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

◆ client_stop()

static void client_stop ( void  )
static

Definition at line 593 of file sock.c.

595{
597 wsa_ok ( closesocket ( mem->s ), 0 ==, "closesocket error (%x): %d\n" );
598 LocalFree ( mem->send_buf );
599 LocalFree ( mem );
600 ExitThread(0);
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define wsa_ok(op, cond, msg)
Definition: sock.c:60

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

◆ compare_addrinfo()

static void compare_addrinfo ( ADDRINFO a,
ADDRINFO b 
)
static

Definition at line 444 of file sock.c.

446{
447 for (; a && b ; a = a->ai_next, b = b->ai_next)
448 {
449 ok(a->ai_flags == b->ai_flags,
450 "Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
451 ok(a->ai_family == b->ai_family,
452 "Wrong family %d != %d\n", a->ai_family, b->ai_family);
453 ok(a->ai_socktype == b->ai_socktype,
454 "Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
455 ok(a->ai_protocol == b->ai_protocol,
456 "Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
457 ok(a->ai_addrlen == b->ai_addrlen,
458 "Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
459 ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
460 "Wrong address data\n");
461 if (a->ai_canonname && b->ai_canonname)
462 {
463 ok(!strcmp(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
464 a->ai_canonname, b->ai_canonname);
465 }
466 else
467 ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
468 a->ai_canonname, b->ai_canonname);
469 }
470 ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define b
Definition: ke_i.h:79

◆ compare_addrinfow()

static void compare_addrinfow ( ADDRINFOW a,
ADDRINFOW b 
)
static

Definition at line 472 of file sock.c.

474{
475 for (; a && b ; a = a->ai_next, b = b->ai_next)
476 {
477 ok(a->ai_flags == b->ai_flags,
478 "Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
479 ok(a->ai_family == b->ai_family,
480 "Wrong family %d != %d\n", a->ai_family, b->ai_family);
481 ok(a->ai_socktype == b->ai_socktype,
482 "Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
483 ok(a->ai_protocol == b->ai_protocol,
484 "Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
485 ok(a->ai_addrlen == b->ai_addrlen,
486 "Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
487 ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
488 "Wrong address data\n");
489 if (a->ai_canonname && b->ai_canonname)
490 {
491 ok(!lstrcmpW(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
492 wine_dbgstr_w(a->ai_canonname), wine_dbgstr_w(b->ai_canonname));
493 }
494 else
495 ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
496 a->ai_canonname, b->ai_canonname);
497 }
498 ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
#define wine_dbgstr_w
Definition: kernel32.h:34
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170

Referenced by test_GetAddrInfoW().

◆ compare_file2()

static void compare_file2 ( HANDLE  handle,
SOCKET  sock,
int  offset,
const char file,
int  line 
)
static

Definition at line 8830 of file sock.c.

8833{
8834 char buf1[256], buf2[256];
8835 BOOL success;
8836 int i = 0;
8837
8839 while (1)
8840 {
8841 DWORD n1 = 0, n2 = 0;
8842
8843 success = ReadFile(handle, buf1, sizeof(buf1), &n1, NULL);
8844 ok_(file,line)(success, "Failed to read from file.\n");
8845 if (success && n1 == 0)
8846 break;
8847 else if(!success)
8848 return;
8849 n2 = recv(sock, buf2, n1, 0);
8850 ok_(file,line)(n1 == n2, "Block %d size mismatch (%d != %d)\n", i, n1, n2);
8851 ok_(file,line)(memcmp(buf1, buf2, n2) == 0, "Block %d failed\n", i);
8852 i++;
#define ok_(x1, x2)
Definition: atltest.h:61
#define FILE_BEGIN
Definition: compat.h:761
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int n2
Definition: dwarfget.c:148
int n1
Definition: dwarfget.c:148
Definition: fci.c:127
Definition: parser.c:49
Definition: tcpcore.h:1455
#define success(from, fromstr, to, tostr)

◆ create_async_message_window()

static HWND create_async_message_window ( void  )
static

Definition at line 9495 of file sock.c.

9498{
9499 static const char class_name[] = "ws2_32 async message window class";
9500
9501 WNDCLASSEXA wndclass;
9502 HWND hWnd;
9503
9504 wndclass.cbSize = sizeof(wndclass);
9505 wndclass.style = CS_HREDRAW | CS_VREDRAW;
9506 wndclass.lpfnWndProc = DefWindowProcA;
9507 wndclass.cbClsExtra = 0;
9508 wndclass.cbWndExtra = 0;
9509 wndclass.hInstance = GetModuleHandleA(NULL);
9512 wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
9513 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
9514 wndclass.lpszClassName = class_name;
9515 wndclass.lpszMenuName = NULL;
9516
9517 RegisterClassExA(&wndclass);
9518
9519 hWnd = CreateWindowA(class_name, "ws2_32 async message window", WS_OVERLAPPEDWINDOW,
9520 0, 0, 500, 500, NULL, NULL, GetModuleHandleA(NULL), NULL);
9521 if (!hWnd)
9522 {
9523 ok(0, "failed to create window: %u\n", GetLastError());
9524 return NULL;
9525 }
9526
HWND hWnd
Definition: settings.c:17
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
int cbClsExtra
Definition: winuser.h:3194
HINSTANCE hInstance
Definition: winuser.h:3196
HCURSOR hCursor
Definition: winuser.h:3198
LPCSTR lpszMenuName
Definition: winuser.h:3200
HICON hIconSm
Definition: winuser.h:3202
UINT style
Definition: winuser.h:3192
int cbWndExtra
Definition: winuser.h:3195
UINT cbSize
Definition: winuser.h:3191
WNDPROC lpfnWndProc
Definition: winuser.h:3193
LPCSTR lpszClassName
Definition: winuser.h:3201
HICON hIcon
Definition: winuser.h:3197
HBRUSH hbrBackground
Definition: winuser.h:3199
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define CS_VREDRAW
Definition: winuser.h:653
#define COLOR_WINDOW
Definition: winuser.h:912
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4305
#define CS_HREDRAW
Definition: winuser.h:648
#define IDC_ARROW
Definition: winuser.h:682
#define IDI_APPLICATION
Definition: winuser.h:699
ATOM WINAPI RegisterClassExA(_In_ CONST WNDCLASSEXA *)
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE hInstance, _In_ LPCSTR lpIconName)
Definition: cursoricon.c:2029
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
const char * LPCSTR
Definition: xmlstorage.h:183

◆ dbgstr_event_seq()

static const char * dbgstr_event_seq ( const LPARAM seq)
static

Definition at line 5565 of file sock.c.

5568{
5569 static char message[1024];
5570 char name[12];
5571 int len = 1;
5572
5573 message[0] = '[';
5574 message[1] = 0;
5575 while (*seq)
5576 {
5578 len += sprintf(message + len, "%s(%d) ", name, WSAGETSELECTERROR(*seq));
5579 seq++;
5580 }
5581 if (len > 1) len--;
5582 strcpy( message + len, "]" );
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static void get_event_details(int event, int *bit, char *name)
Definition: sock.c:5531
Definition: tftpd.h:60
Definition: name.c:39
#define WSAGETSELECTERROR(l)
Definition: winsock.h:482
#define WSAGETSELECTEVENT(l)
Definition: winsock.h:481

Referenced by ok_event_sequence().

◆ dbgstr_event_seq_result()

static char * dbgstr_event_seq_result ( SOCKET  s,
WSANETWORKEVENTS netEvents 
)
static

Definition at line 5584 of file sock.c.

5587{
5588 static char message[1024];
5589 struct async_message *curr = messages_received;
5590 int index, error, bit = 0;
5591 char name[12];
5592 int len = 1;
5593
5594 message[0] = '[';
5595 message[1] = 0;
5596 while (1)
5597 {
5598 if (netEvents)
5599 {
5600 if (bit >= FD_MAX_EVENTS) break;
5601 if ( !(netEvents->lNetworkEvents & (1 << bit)) )
5602 {
5603 bit++;
5604 continue;
5605 }
5606 get_event_details(1 << bit, &index, name);
5607 error = netEvents->iErrorCode[index];
5608 bit++;
5609 }
5610 else
5611 {
5612 if (!curr) break;
5613 if (curr->socket != s)
5614 {
5615 curr = curr->next;
5616 continue;
5617 }
5620 curr = curr->next;
5621 }
5622
5623 len += sprintf(message + len, "%s(%d) ", name, error);
5624 }
5625 if (len > 1) len--;
5626 strcpy( message + len, "]" );
#define index(s, c)
Definition: various.h:29
GLdouble s
Definition: gl.h:2039
GLuint index
Definition: glext.h:6031
#define error(str)
Definition: mkdosfs.c:1605
static struct async_message * messages_received
Definition: sock.c:5502
int iErrorCode[FD_MAX_EVENTS]
Definition: winsock2.h:644
SOCKET socket
Definition: sock.c:5497
LPARAM lparam
Definition: sock.c:5498
struct async_message * next
Definition: sock.c:5499
#define FD_MAX_EVENTS
Definition: winsock2.h:313

Referenced by ok_event_sequence().

◆ do_bind()

static void do_bind ( SOCKET  s,
struct sockaddr addr,
int  addrlen 
)
static

Definition at line 507 of file sock.c.

509{
510 int err, wsaerr = 0, n_try = BIND_TRIES;
511
512 while ( ( err = bind ( s, addr, addrlen ) ) != 0 &&
513 ( wsaerr = WSAGetLastError () ) == WSAEADDRINUSE &&
514 n_try-- >= 0)
515 {
516 trace ( "address in use, waiting ...\n" );
517 Sleep ( 1000 * BIND_SLEEP );
518 }
519 ok ( err == 0, "failed to bind: %d\n", wsaerr );
#define trace
Definition: atltest.h:70
GLenum const GLvoid * addr
Definition: glext.h:9621
#define BIND_TRIES
Definition: sock.c:49
#define BIND_SLEEP
Definition: sock.c:48
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define WSAEADDRINUSE
Definition: winerror.h:1961

Referenced by server_start().

◆ do_getservbyname()

static DWORD WINAPI do_getservbyname ( void param)
static

Definition at line 2347 of file sock.c.

2350{
2351 struct {
2352 const char *name;
2353 const char *proto;
2354 int port;
2355 } serv[2] = { {"domain", "udp", 53}, {"telnet", "tcp", 23} };
2356
2357 HANDLE *starttest = param;
2358 int i, j;
2359 struct servent *pserv[2];
2360
2361 ok ( WaitForSingleObject ( *starttest, TEST_TIMEOUT * 1000 ) != WAIT_TIMEOUT,
2362 "test_getservbyname: timeout waiting for start signal\n" );
2363
2364 /* ensure that necessary buffer resizes are completed */
2365 for ( j = 0; j < 2; j++) {
2366 pserv[j] = getservbyname ( serv[j].name, serv[j].proto );
2367 }
2368
2369 for ( i = 0; i < NUM_QUERIES / 2; i++ ) {
2370 for ( j = 0; j < 2; j++ ) {
2371 pserv[j] = getservbyname ( serv[j].name, serv[j].proto );
2372 ok ( pserv[j] != NULL || broken(pserv[j] == NULL) /* win8, fixed in win81 */,
2373 "getservbyname could not retrieve information for %s: %d\n", serv[j].name, WSAGetLastError() );
2374 if ( !pserv[j] ) continue;
2375 ok ( pserv[j]->s_port == htons(serv[j].port),
2376 "getservbyname returned the wrong port for %s: %d\n", serv[j].name, ntohs(pserv[j]->s_port) );
2377 ok ( !strcmp ( pserv[j]->s_proto, serv[j].proto ),
2378 "getservbyname returned the wrong protocol for %s: %s\n", serv[j].name, pserv[j]->s_proto );
2379 ok ( !strcmp ( pserv[j]->s_name, serv[j].name ),
2380 "getservbyname returned the wrong name for %s: %s\n", serv[j].name, pserv[j]->s_name );
2381 }
2382
2383 ok ( pserv[0] == pserv[1] || broken(pserv[0] != pserv[1]) /* win8, fixed in win81 */,
2384 "getservbyname: winsock resized servent buffer when not necessary\n" );
2385 }
2386
static const CHAR s_name[]
Definition: ShowWindow.c:19
#define broken(x)
Definition: _sntprintf.h:21
#define WAIT_TIMEOUT
Definition: dderror.h:14
USHORT port
Definition: uri.c:228
PSERVENT WSAAPI getservbyname(IN const char FAR *name, IN const char FAR *proto)
Definition: getxbyxx.c:500
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define ntohs(x)
Definition: module.h:210
#define NUM_QUERIES
Definition: sock.c:55
#define TEST_TIMEOUT
Definition: sock.c:50
short s_port
Definition: winsock.h:165
char * s_proto
Definition: winsock.h:166

◆ do_synchronous_recv()

static int do_synchronous_recv ( SOCKET  s,
char buf,
int  buflen,
int  flags,
int  recvlen 
)
static

Definition at line 406 of file sock.c.

408{
409 char* last = buf + buflen, *p;
410 int n = 1;
411 for ( p = buf; n > 0 && p < last; )
412 {
413 n = recv ( s, p, min ( recvlen, last - p ), flags );
414 if (n > 0) p += n;
415 }
416 wsa_ok ( n, 0 <=, "do_synchronous_recv (%x): error %d:\n" );
417 return p - buf;
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLfloat GLfloat p
Definition: glext.h:8902
POINT last
Definition: font.c:46

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

◆ do_synchronous_recvfrom()

static int do_synchronous_recvfrom ( SOCKET  s,
char buf,
int  buflen,
int  flags,
struct sockaddr from,
int fromlen,
int  recvlen 
)
static

Definition at line 419 of file sock.c.

421{
422 char* last = buf + buflen, *p;
423 int n = 1;
424 for ( p = buf; n > 0 && p < last; )
425 {
426 n = recvfrom ( s, p, min ( recvlen, last - p ), flags, from, fromlen );
427 if (n > 0) p += n;
428 }
429 wsa_ok ( n, 0 <=, "do_synchronous_recv (%x): error %d:\n" );
430 return p - buf;
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
CardRegion * from
Definition: spigame.cpp:19

Referenced by simple_mixed_client().

◆ do_synchronous_send()

static int do_synchronous_send ( SOCKET  s,
char buf,
int  buflen,
int  flags,
int  sendlen 
)
static

Definition at line 393 of file sock.c.

395{
396 char* last = buf + buflen, *p;
397 int n = 1;
398 for ( p = buf; n > 0 && p < last; )
399 {
400 n = send ( s, p, min ( sendlen, last - p ), flags );
401 if (n > 0) p += n;
402 }
403 wsa_ok ( n, 0 <=, "do_synchronous_send (%x): error %d\n" );
404 return p - buf;
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23

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

◆ do_test()

static void do_test ( test_setup test)
static

Definition at line 1362 of file sock.c.

1364{
1365 DWORD i, n = min (test->general.n_clients, MAX_CLIENTS);
1366 DWORD wait;
1367
1369 for (i = 0; i <= n; i++)
1371
1372 StartServer ( test->srv, &test->general, &test->srv_params );
1373 StartClients ( test->clt, &test->general, &test->clt_params );
1375
1376 wait = WaitForMultipleObjects ( 1 + n, thread, TRUE, 1000 * TEST_TIMEOUT );
1377 ok ( wait <= WAIT_OBJECT_0 + n ,
1378 "some threads have not completed: %x\n", wait );
1379
1380 if ( ! ( wait <= WAIT_OBJECT_0 + n ) )
1381 {
1382 for (i = 0; i <= n; i++)
1383 {
1384 if ( WaitForSingleObject ( thread[i], 0 ) != WAIT_OBJECT_0 )
1385 {
1386 trace ("terminating thread %08x\n", thread_id[i]);
1387 TerminateThread ( thread [i], 0 );
1388 }
1389 }
1390 }
1392 for (i = 0; i <= n; i++)
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:587
#define test
Definition: rosglue.h:37
static DWORD thread_id[1+MAX_CLIENTS]
Definition: sock.c:231
static HANDLE thread[1+MAX_CLIENTS]
Definition: sock.c:230
static void StartClients(LPTHREAD_START_ROUTINE routine, test_params *general, client_params *par)
Definition: sock.c:1347
static void StartServer(LPTHREAD_START_ROUTINE routine, test_params *general, server_params *par)
Definition: sock.c:1339
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
#define WAIT_OBJECT_0
Definition: winbase.h:406

◆ drain_socket_thread()

static DWORD WINAPI drain_socket_thread ( LPVOID  arg)
static

Definition at line 5328 of file sock.c.

5331{
5332 char buffer[1024];
5333 SOCKET sock = *(SOCKET*)arg;
5334 int ret;
5335
5336 while ((ret = recv(sock, buffer, sizeof(buffer), 0)) != 0)
5337 {
5338 if (ret < 0)
5339 {
5341 {
5342 fd_set readset;
5343 FD_ZERO(&readset);
5344 FD_SET(sock, &readset);
5345 select(sock+1, &readset, NULL, NULL, NULL);
5346 while (drain_pause)
5347 Sleep(100);
5348 }
5349 else
5350 break;
5351 }
5352 }
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
GLuint buffer
Definition: glext.h:5915
static BOOL drain_pause
Definition: sock.c:5327
Definition: winsock.h:66
int ret
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

Referenced by test_events().

◆ DWORD()

static DWORD ( WINAPI pGetAdaptersInfo)
static

◆ event_client()

static void WINAPI event_client ( client_params par)
static

Definition at line 1043 of file sock.c.

1045{
1046 test_params *gen = par->general;
1048 int id = GetCurrentThreadId(), n_expected = gen->n_chunks * gen->chunk_size,
1049 tmp, err, n;
1050 HANDLE event;
1051 WSANETWORKEVENTS wsa_events;
1052 char *send_last, *recv_last, *send_p, *recv_p;
1054
1055 trace ( "event_client (%x): starting\n", id );
1056 client_start ( par );
1057 trace ( "event_client (%x): server ready\n", id );
1058
1059 mem = TlsGetValue ( tls );
1060
1061 /* Prepare event notification for connect, makes socket nonblocking */
1062 event = WSACreateEvent ();
1064 tmp = connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) );
1065 if ( tmp != 0 ) {
1066 err = WSAGetLastError ();
1067 ok ( err == WSAEWOULDBLOCK, "event_client (%x): connect error: %d\n", id, err );
1069 ok ( tmp == WAIT_OBJECT_0, "event_client (%x): wait for connect event failed: %d\n", id, tmp );
1070 err = WSAEnumNetworkEvents ( mem->s, event, &wsa_events );
1071 ok ( err == 0, "event_client (%x): WSAEnumNetworkEvents error: %d\n", id, err );
1072 err = wsa_events.iErrorCode[ FD_CONNECT_BIT ];
1073 ok ( err == 0, "event_client (%x): connect error: %d\n", id, err );
1074 if ( err ) goto out;
1075 }
1076
1077 trace ( "event_client (%x) connected\n", id );
1078
1079 WSAEventSelect ( mem->s, event, mask );
1080
1081 recv_p = mem->recv_buf;
1082 recv_last = mem->recv_buf + n_expected;
1083 send_p = mem->send_buf;
1084 send_last = mem->send_buf + n_expected;
1085
1086 while ( TRUE )
1087 {
1089 ok ( err == WAIT_OBJECT_0, "event_client (%x): wait failed\n", id );
1090
1091 err = WSAEnumNetworkEvents ( mem->s, event, &wsa_events );
1092 ok( err == 0, "event_client (%x): WSAEnumNetworkEvents error: %d\n", id, err );
1093
1094 if ( wsa_events.lNetworkEvents & FD_WRITE )
1095 {
1096 err = wsa_events.iErrorCode[ FD_WRITE_BIT ];
1097 ok ( err == 0, "event_client (%x): FD_WRITE error code: %d\n", id, err );
1098
1099 if ( err== 0 )
1100 do
1101 {
1102 n = send ( mem->s, send_p, min ( send_last - send_p, par->buflen ), 0 );
1103 if ( n < 0 )
1104 {
1105 err = WSAGetLastError ();
1106 ok ( err == WSAEWOULDBLOCK, "event_client (%x): send error: %d\n", id, err );
1107 }
1108 else
1109 send_p += n;
1110 }
1111 while ( n >= 0 && send_p < send_last );
1112
1113 if ( send_p == send_last )
1114 {
1115 trace ( "event_client (%x): all data sent - shutdown\n", id );
1116 shutdown ( mem->s, SD_SEND );
1117 mask &= ~FD_WRITE;
1118 WSAEventSelect ( mem->s, event, mask );
1119 }
1120 }
1121 if ( wsa_events.lNetworkEvents & FD_READ )
1122 {
1123 err = wsa_events.iErrorCode[ FD_READ_BIT ];
1124 ok ( err == 0, "event_client (%x): FD_READ error code: %d\n", id, err );
1125 if ( err != 0 ) break;
1126
1127 /* First read must succeed */
1128 n = recv ( mem->s, recv_p, min ( recv_last - recv_p, par->buflen ), 0 );
1129 wsa_ok ( n, 0 <=, "event_client (%x): recv error: %d\n" );
1130
1131 while ( n >= 0 ) {
1132 recv_p += n;
1133 if ( recv_p == recv_last )
1134 {
1135 mask &= ~FD_READ;
1136 trace ( "event_client (%x): all data received\n", id );
1137 WSAEventSelect ( mem->s, event, mask );
1138 break;
1139 }
1140 n = recv ( mem->s, recv_p, min ( recv_last - recv_p, par->buflen ), 0 );
1141 if ( n < 0 && ( err = WSAGetLastError()) != WSAEWOULDBLOCK )
1142 ok ( 0, "event_client (%x): read error: %d\n", id, err );
1143
1144 }
1145 }
1146 if ( wsa_events.lNetworkEvents & FD_CLOSE )
1147 {
1148 trace ( "event_client (%x): close event\n", id );
1149 err = wsa_events.iErrorCode[ FD_CLOSE_BIT ];
1150 ok ( err == 0, "event_client (%x): FD_CLOSE error code: %d\n", id, err );
1151 break;
1152 }
1153 }
1154
1155 n = send_p - mem->send_buf;
1156 ok ( send_p == send_last,
1157 "simple_client (%x): sent less data than expected: %d of %d\n", id, n, n_expected );
1158 n = recv_p - mem->recv_buf;
1159 ok ( recv_p == recv_last,
1160 "simple_client (%x): received less data than expected: %d of %d\n", id, n, n_expected );
1161 n = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
1162 ok ( n == -1, "event_client (%x): test pattern error: %d\n", id, n);
1163
1164out:
1165 WSACloseEvent ( event );
1166 trace ( "event_client (%x) exiting\n", id );
1167 client_stop ();
static TCHAR test_buffer[TEST_BUFFER_SIZE]
Definition: _tfileio.c:53
BOOL WSAAPI WSACloseEvent(IN WSAEVENT hEvent)
Definition: event.c:23
INT WSAAPI WSAEnumNetworkEvents(IN SOCKET s, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents)
Definition: event.c:94
INT WSAAPI WSAEventSelect(IN SOCKET s, IN WSAEVENT hEventObject, IN LONG lNetworkEvents)
Definition: select.c:182
struct _cl_event * event
Definition: glext.h:7739
GLenum GLint GLuint mask
Definition: glext.h:6028
long LONG
Definition: pedump.c:60
static FILE * out
Definition: regtests2xml.c:44
static void client_stop(void)
Definition: sock.c:593
static void client_start(client_params *par)
Definition: sock.c:566
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
int buflen
Definition: sock.c:150
#define FD_CONNECT_BIT
Definition: winsock2.h:301
#define FD_CLOSE_BIT
Definition: winsock2.h:303
#define FD_READ_BIT
Definition: winsock2.h:293
WINSOCK_API_LINKAGE WSAEVENT WSAAPI WSACreateEvent(void)
Definition: event.c:42
#define FD_WRITE_BIT
Definition: winsock2.h:295
#define FD_READ
Definition: winsock.h:405
#define FD_WRITE
Definition: winsock.h:406
#define FD_CLOSE
Definition: winsock.h:410
#define SD_SEND
Definition: winsock.h:55
#define FD_CONNECT
Definition: winsock.h:409
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

◆ Exit()

static void Exit ( void  )
static

Definition at line 1330 of file sock.c.

1332{
1333 INT ret, err;
1334 TlsFree ( tls );
1335 ret = WSACleanup();
1336 err = WSAGetLastError();
1337 ok ( ret == 0, "WSACleanup failed ret = %d GetLastError is %d\n", ret, err);
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1166
int32_t INT
Definition: typedefs.h:58
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60

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(), AcpiEvExecuteOrphanRegMethod(), AcpiExCreateMethod(), AcpiExInsertIntoField(), AcpiExReadDataFromField(), AcpiExResolveMultiple(), AcpiHwClearAcpiStatus(), AcpiHwRegisterWrite(), AcpiInstallSciHandler(), AcpiNsCheckReturnValue(), AcpiRsConvertAmlToResource(), AcpiRsConvertResourceToAml(), AcpiTbInstallAndLoadTable(), AcpiUtAllocateOwnerId(), af_autofitter_load_glyph(), 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(), ClasspAccessAlignmentProperty(), ClasspDeviceGetBlockDeviceCharacteristicsVPDPage(), ClasspDeviceGetBlockLimitsVPDPage(), ClasspDeviceGetLBAStatus(), ClasspDeviceGetLBAStatusWorker(), ClasspDeviceGetLBProvisioningVPDPage(), ClasspDeviceLBProvisioningProperty(), ClasspDeviceSeekPenaltyProperty(), ClasspDeviceTrimProcess(), ClasspDeviceTrimProperty(), ClassReadWrite(), CmpCreateLinkNode(), CmpDoCreate(), CmpGetSymbolicLink(), CmpRemoveSubKey(), co_HOOK_CallHooks(), co_IntProcessKeyboardMessage(), co_MsqDispatchOneSentMessage(), CommonInstall(), CreateDIBitmap(), DefSetText(), DeviceProcessDsmTrimRequest(), FxInterrupt::Disconnect(), DispTdiQueryIpHwAddress(), DoAppSwitch(), DriverEvtDeviceAdd(), EngCreateWnd(), EnumHKCRKey(), EnumHKCRValue(), fnt_face_get_dll_font(), FNT_Face_Init(), fnt_font_load(), FNT_Load_Glyph(), FreeDeviceData(), FsRtlIsDbcsInExpression(), FsRtlIsNameInExpressionPrivate(), 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(), GdiConvertEnhMetaFile(), GdiConvertMetaFilePict(), GdiCreateLocalEnhMetaFile(), GdiCreateLocalMetaFilePict(), 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(), HalpGetRootInterruptVector(), hash_insert(), hash_rehash(), Horizontal_Sweep_Drop(), IntCallWindowProcA(), IntCallWindowProcW(), LdrpCreateDllSection(), CSettings::Load(), load_truetype_glyph(), main(), MapAnsiQuerySetToUnicode(), MapUnicodeQuerySetToAnsi(), MiDoMappedCopy(), MiDoPoolCopy(), MmPapAllocatePagesInRange(), NtAreMappedFilesTheSame(), NtGdiExtEscape(), NtGdiGetFontUnicodeRanges(), NtGdiGetGlyphOutline(), NtGdiSelectClipPath(), NtGdiSetDIBitsToDeviceInternal(), NtGdiSetPixelFormat(), NtGdiSwapBuffers(), NtSetSystemPowerState(), NtStopProfile(), NtUserAttachThreadInput(), NtUserBuildPropList(), NtUserCallHwndLock(), NtUserCallHwndParamLock(), 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(), PreloadGlobalMessageTable(), ProgressCountdown(), 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_skip_PS_token(), ps_parser_to_bytes(), ps_table_new(), ps_tocoordarray(), ps_tofixedarray(), psh_glyph_init(), psh_hint_table_init(), RegCreateKeyExA(), RegEnumKeyExA(), RegEnumValueA(), RegLoadKeyA(), RegReplaceKeyA(), RtlGetNtProductType(), RtlpLookupDynamicFunctionEntry(), RtlVirtualUnwind(), SetDIBitsToDevice(), sfnt_load_face(), START_TEST(), StretchDIBits(), 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(), T42_Face_Init(), t42_load_keyword(), T42_Open_Face(), t42_parse_dict(), t42_parse_sfnts(), t42_parser_init(), Test_Overread(), TestIrpHandler(), TreeListKeyDown(), 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().

◆ fill_buffer()

static void fill_buffer ( char buf,
int  chunk_size,
int  n_chunks 
)
static

Definition at line 361 of file sock.c.

363{
364 char c, *p;
365 for ( c = FIRST_CHAR, p = buf; c < FIRST_CHAR + n_chunks; c++, p += chunk_size )
366 memset ( p, c, chunk_size );
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define memset(x, y, z)
Definition: compat.h:39
#define FIRST_CHAR
Definition: sock.c:47

Referenced by client_start().

◆ flush_events()

static void flush_events ( SOCKET  s,
HANDLE  hEvent 
)
static

Definition at line 5628 of file sock.c.

5631{
5632 WSANETWORKEVENTS netEvents;
5633 struct async_message *prev = NULL, *curr = messages_received;
5634 int ret;
5635 DWORD dwRet;
5636
5638 {
5639 dwRet = WaitForSingleObject(hEvent, 100);
5640 if (dwRet == WAIT_OBJECT_0)
5641 {
5642 ret = WSAEnumNetworkEvents(s, hEvent, &netEvents);
5643 if (ret)
5644 ok(0, "WSAEnumNetworkEvents failed, error %d\n", ret);
5645 }
5646 }
5647 else
5648 {
5649 while (curr)
5650 {
5651 if (curr->socket == s)
5652 {
5653 if (prev) prev->next = curr->next;
5654 else messages_received = curr->next;
5655
5656 HeapFree(GetProcessHeap(), 0, curr);
5657
5658 if (prev) curr = prev->next;
5659 else curr = messages_received;
5660 }
5661 else
5662 {
5663 prev = curr;
5664 curr = curr->next;
5665 }
5666 }
#define GetProcessHeap()
Definition: compat.h:736
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapFree(x, y, z)
Definition: compat.h:735
static HANDLE hEvent
Definition: comm.c:54

◆ get_event_details()

static void get_event_details ( int  event,
int bit,
char name 
)
static

Definition at line 5531 of file sock.c.

5534{
5535 switch (event)
5536 {
5537 case FD_ACCEPT:
5538 if (bit) *bit = FD_ACCEPT_BIT;
5539 if (name) strcpy(name, "FD_ACCEPT");
5540 break;
5541 case FD_CONNECT:
5542 if (bit) *bit = FD_CONNECT_BIT;
5543 if (name) strcpy(name, "FD_CONNECT");
5544 break;
5545 case FD_READ:
5546 if (bit) *bit = FD_READ_BIT;
5547 if (name) strcpy(name, "FD_READ");
5548 break;
5549 case FD_OOB:
5550 if (bit) *bit = FD_OOB_BIT;
5551 if (name) strcpy(name, "FD_OOB");
5552 break;
5553 case FD_WRITE:
5554 if (bit) *bit = FD_WRITE_BIT;
5555 if (name) strcpy(name, "FD_WRITE");
5556 break;
5557 case FD_CLOSE:
5558 if (bit) *bit = FD_CLOSE_BIT;
5559 if (name) strcpy(name, "FD_CLOSE");
5560 break;
5561 default:
5562 if (bit) *bit = -1;
5563 if (name) sprintf(name, "bad%x", event);
#define FD_OOB_BIT
Definition: winsock2.h:297
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
#define FD_OOB
Definition: winsock.h:407
#define FD_ACCEPT
Definition: winsock.h:408

◆ gethostname()

int WINAPI gethostname ( char name,
int  namelen 
)

Referenced by test_gethostbyname().

◆ inet_ntoa_thread_proc()

static DWORD WINAPI inet_ntoa_thread_proc ( void param)
static

Definition at line 10541 of file sock.c.

10544{
10545 ULONG addr;
10546 const char *str;
10547 HANDLE *event = param;
10548
10549 addr = inet_addr("4.3.2.1");
10550 ok(addr == htonl(0x04030201), "expected 0x04030201, got %08x\n", addr);
10551 str = inet_ntoa(*(struct in_addr *)&addr);
10552 ok(!strcmp(str, "4.3.2.1"), "expected 4.3.2.1, got %s\n", str);
10553
10554 SetEvent(event[0]);
10555 WaitForSingleObject(event[1], 3000);
10556
#define inet_ntoa(addr)
Definition: inet.h:100
#define htonl(x)
Definition: module.h:214
const WCHAR * str
Definition: tcpip.h:126
uint32_t ULONG
Definition: typedefs.h:59

◆ Init()

static void Init ( void  )
static

Definition at line 1287 of file sock.c.

1289{
1290 WORD ver = MAKEWORD (2, 2);
1291 WSADATA data;
1292 HMODULE hws2_32 = GetModuleHandleA("ws2_32.dll"), hiphlpapi, ntdll;
1293
1294 pfreeaddrinfo = (void *)GetProcAddress(hws2_32, "freeaddrinfo");
1295 pgetaddrinfo = (void *)GetProcAddress(hws2_32, "getaddrinfo");
1296 pFreeAddrInfoW = (void *)GetProcAddress(hws2_32, "FreeAddrInfoW");
1297 pFreeAddrInfoExW = (void *)GetProcAddress(hws2_32, "FreeAddrInfoExW");
1298 pGetAddrInfoW = (void *)GetProcAddress(hws2_32, "GetAddrInfoW");
1299 pGetAddrInfoExW = (void *)GetProcAddress(hws2_32, "GetAddrInfoExW");
1300 pGetAddrInfoExOverlappedResult = (void *)GetProcAddress(hws2_32, "GetAddrInfoExOverlappedResult");
1301 pInetNtop = (void *)GetProcAddress(hws2_32, "inet_ntop");
1302 pInetNtopW = (void *)GetProcAddress(hws2_32, "InetNtopW");
1303 pInetPtonA = (void *)GetProcAddress(hws2_32, "inet_pton");
1304 pInetPtonW = (void *)GetProcAddress(hws2_32, "InetPtonW");
1305 pWSALookupServiceBeginW = (void *)GetProcAddress(hws2_32, "WSALookupServiceBeginW");
1306 pWSALookupServiceEnd = (void *)GetProcAddress(hws2_32, "WSALookupServiceEnd");
1307 pWSALookupServiceNextW = (void *)GetProcAddress(hws2_32, "WSALookupServiceNextW");
1308 pWSAEnumNameSpaceProvidersA = (void *)GetProcAddress(hws2_32, "WSAEnumNameSpaceProvidersA");
1309 pWSAEnumNameSpaceProvidersW = (void *)GetProcAddress(hws2_32, "WSAEnumNameSpaceProvidersW");
1310 pWSAPoll = (void *)GetProcAddress(hws2_32, "WSAPoll");
1311
1312 hiphlpapi = LoadLibraryA("iphlpapi.dll");
1313 if (hiphlpapi)
1314 {
1315 pGetIpForwardTable = (void *)GetProcAddress(hiphlpapi, "GetIpForwardTable");
1316 pGetAdaptersInfo = (void *)GetProcAddress(hiphlpapi, "GetAdaptersInfo");
1317 }
1318
1319 ntdll = LoadLibraryA("ntdll.dll");
1320 if (ntdll)
1321 {
1322 pNtClose = (void *)GetProcAddress(ntdll, "NtClose");
1323 pNtSetInformationFile = (void *)GetProcAddress(ntdll, "NtSetInformationFile");
1324 pNtQueryInformationFile = (void *)GetProcAddress(ntdll, "NtQueryInformationFile");
1325 }
1326
1327 ok ( WSAStartup ( ver, &data ) == 0, "WSAStartup failed\n" );
1328 tls = TlsAlloc();
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1100
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
unsigned short WORD
Definition: ntddk_ex.h:93
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define MAKEWORD(a, b)
Definition: typedefs.h:248

◆ int()

static int ( WINAPI pgetaddrinfo)
static

◆ io_completion()

static void WINAPI io_completion ( DWORD  error,
DWORD  transferred,
WSAOVERLAPPED overlapped,
DWORD  flags 
)
static

Definition at line 6740 of file sock.c.

6743{

◆ iocp_async_closesocket()

static void iocp_async_closesocket ( SOCKET  src)
static

Definition at line 11142 of file sock.c.

11145{
11146 HANDLE port;
11147 WSAOVERLAPPED *ovl_iocp;
11148 int ret;
11149 DWORD bytes;
11150 ULONG_PTR key;
11151 HWND hwnd;
11152 MSG msg;
11153
11154 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
11155 0, 0, 0, 0, NULL, NULL, 0, NULL);
11156 ok(hwnd != 0, "CreateWindowEx failed\n");
11157
11159 ok(!ret, "got %d\n", ret);
11160
11161 Sleep(100);
11162 memset(&msg, 0, sizeof(msg));
11164 ok(ret, "got %d\n", ret);
11165 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11166 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11167 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11168 ok(msg.lParam == 2, "got %08lx\n", msg.lParam);
11169
11170 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
11171 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
11172
11173 Sleep(100);
11175 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11176
11177 bytes = 0xdeadbeef;
11178 key = 0xdeadbeef;
11179 ovl_iocp = (void *)0xdeadbeef;
11180 SetLastError(0xdeadbeef);
11181 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11182 ok(!ret, "got %d\n", ret);
11183 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11184 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11185 ok(key == 0xdeadbeef, "got key %lu\n", key);
11186 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11187
11188 Sleep(100);
11190 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11191
11193
11194 Sleep(100);
11195 memset(&msg, 0, sizeof(msg));
11197 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11198
11199 bytes = 0xdeadbeef;
11200 key = 0xdeadbeef;
11201 ovl_iocp = (void *)0xdeadbeef;
11202 SetLastError(0xdeadbeef);
11203 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11204 ok(!ret, "got %d\n", ret);
11205 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11206 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11207 ok(key == 0xdeadbeef, "got key %lu\n", key);
11208 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11209
11211
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define SetLastError(x)
Definition: compat.h:752
INT WSAAPI WSAAsyncSelect(IN SOCKET s, IN HWND hWnd, IN UINT wMsg, IN LONG lEvent)
Definition: select.c:134
GLenum src
Definition: glext.h:6340
HANDLE WINAPI CreateIoCompletionPort(IN HANDLE FileHandle, IN HANDLE ExistingCompletionPort, IN ULONG_PTR CompletionKey, IN DWORD NumberOfConcurrentThreads)
Definition: iocompl.c:65
BOOL WINAPI GetQueuedCompletionStatus(IN HANDLE CompletionHandle, IN LPDWORD lpNumberOfBytesTransferred, OUT PULONG_PTR lpCompletionKey, OUT LPOVERLAPPED *lpOverlapped, IN DWORD dwMilliseconds)
Definition: iocompl.c:131
#define WS_POPUP
Definition: pedump.c:616
#define WM_SOCKET
Definition: sock.c:5504
Definition: copy.c:22
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define PM_REMOVE
Definition: winuser.h:1186
BOOL WINAPI PeekMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)

◆ iocp_async_read()

static void iocp_async_read ( SOCKET  src,
SOCKET  dst 
)
static

Definition at line 10931 of file sock.c.

10934{
10935 HANDLE port;
10936 WSAOVERLAPPED ovl, *ovl_iocp;
10937 WSABUF buf;
10938 int ret;
10939 char data[512];
10940 DWORD flags, bytes;
10941 ULONG_PTR key;
10942
10943 memset(data, 0, sizeof(data));
10944 memset(&ovl, 0, sizeof(ovl));
10945
10946 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
10947 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
10948
10949 buf.len = sizeof(data);
10950 buf.buf = data;
10951 bytes = 0xdeadbeef;
10952 flags = 0;
10953 SetLastError(0xdeadbeef);
10954 ret = WSARecv(src, &buf, 1, &bytes, &flags, &ovl, NULL);
10955 ok(ret == SOCKET_ERROR, "got %d\n", ret);
10956 ok(GetLastError() == ERROR_IO_PENDING, "got %u\n", GetLastError());
10957 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
10958
10959 bytes = 0xdeadbeef;
10960 key = 0xdeadbeef;
10961 ovl_iocp = (void *)0xdeadbeef;
10962 SetLastError(0xdeadbeef);
10963 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
10964 ok(!ret, "got %d\n", ret);
10965 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
10966 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
10967 ok(key == 0xdeadbeef, "got key %#lx\n", key);
10968 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
10969
10970 ret = send(dst, "Hello World!", 12, 0);
10971 ok(ret == 12, "send returned %d\n", ret);
10972
10973 bytes = 0xdeadbeef;
10974 key = 0xdeadbeef;
10975 ovl_iocp = NULL;
10976 SetLastError(0xdeadbeef);
10977 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
10978 ok(ret, "got %d\n", ret);
10979 ok(bytes == 12, "got bytes %u\n", bytes);
10980 ok(key == 0x12345678, "got key %#lx\n", key);
10981 ok(ovl_iocp == &ovl, "got ovl %p\n", ovl_iocp);
10982 if (ovl_iocp)
10983 {
10984 ok(ovl_iocp->InternalHigh == 12, "got %#lx\n", ovl_iocp->InternalHigh);
10985 ok(!ovl_iocp->Internal , "got %#lx\n", ovl_iocp->Internal);
10986 ok(!memcmp(data, "Hello World!", 12), "got %u bytes (%*s)\n", bytes, bytes, data);
10987 }
10988
10989 bytes = 0xdeadbeef;
10990 key = 0xdeadbeef;
10991 ovl_iocp = (void *)0xdeadbeef;
10992 SetLastError(0xdeadbeef);
10993 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
10994 ok(!ret, "got %d\n", ret);
10995 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
10996 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
10997 ok(key == 0xdeadbeef, "got key %#lx\n", key);
10998 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
10999
#define ERROR_IO_PENDING
Definition: dderror.h:15
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
GLenum GLenum dst
Definition: glext.h:6340
DWORD InternalHigh
Definition: winsock2.h:610
DWORD Internal
Definition: winsock2.h:609
#define SOCKET_ERROR
Definition: winsock.h:333

◆ iocp_async_read_closesocket()

static void iocp_async_read_closesocket ( SOCKET  src,
int  how_to_close 
)
static

Definition at line 11001 of file sock.c.

11004{
11005 HANDLE port;
11006 WSAOVERLAPPED ovl, *ovl_iocp;
11007 WSABUF buf;
11008 int ret;
11009 char data[512];
11010 DWORD flags, bytes;
11011 ULONG_PTR key;
11012 HWND hwnd;
11013 MSG msg;
11014
11015 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
11016 0, 0, 0, 0, NULL, NULL, 0, NULL);
11017 ok(hwnd != 0, "CreateWindowEx failed\n");
11018
11020 ok(!ret, "got %d\n", ret);
11021
11022 Sleep(100);
11023 memset(&msg, 0, sizeof(msg));
11025 ok(ret, "got %d\n", ret);
11026 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11027 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11028 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11029 ok(msg.lParam == 2, "got %08lx\n", msg.lParam);
11030
11031 memset(data, 0, sizeof(data));
11032 memset(&ovl, 0, sizeof(ovl));
11033
11034 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
11035 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
11036
11037 Sleep(100);
11039 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11040
11041 buf.len = sizeof(data);
11042 buf.buf = data;
11043 bytes = 0xdeadbeef;
11044 flags = 0;
11045 SetLastError(0xdeadbeef);
11046 ret = WSARecv(src, &buf, 1, &bytes, &flags, &ovl, NULL);
11047 ok(ret == SOCKET_ERROR, "got %d\n", ret);
11048 ok(GetLastError() == ERROR_IO_PENDING, "got %u\n", GetLastError());
11049 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11050
11051 Sleep(100);
11053 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11054
11055 bytes = 0xdeadbeef;
11056 key = 0xdeadbeef;
11057 ovl_iocp = (void *)0xdeadbeef;
11058 SetLastError(0xdeadbeef);
11059 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11060 ok(!ret, "got %d\n", ret);
11061 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11062 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11063 ok(key == 0xdeadbeef, "got key %#lx\n", key);
11064 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11065
11066 Sleep(100);
11068 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11069
11070 switch (how_to_close)
11071 {
11072 case 0:
11074 break;
11075 case 1:
11077 break;
11078 case 2:
11079 pNtClose((HANDLE)src);
11080 break;
11081 default:
11082 ok(0, "wrong value %d\n", how_to_close);
11083 break;
11084 }
11085
11086 Sleep(200);
11087 memset(&msg, 0, sizeof(msg));
11089 switch (how_to_close)
11090 {
11091 case 0:
11092 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11093 break;
11094 case 1:
11095 case 2:
11097{
11098 ok(ret, "got %d\n", ret);
11099 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11100 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11101 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11102 ok(msg.lParam == 0x20, "got %08lx\n", msg.lParam);
11103}
11104 break;
11105 default:
11106 ok(0, "wrong value %d\n", how_to_close);
11107 break;
11108 }
11109
11110 bytes = 0xdeadbeef;
11111 key = 0xdeadbeef;
11112 ovl_iocp = NULL;
11113 SetLastError(0xdeadbeef);
11114 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11115 ok(!ret, "got %d\n", ret);
11118 ok(!bytes, "got bytes %u\n", bytes);
11119 ok(key == 0x12345678, "got key %#lx\n", key);
11120 ok(ovl_iocp == &ovl, "got ovl %p\n", ovl_iocp);
11121 if (ovl_iocp)
11122 {
11123 ok(!ovl_iocp->InternalHigh, "got %#lx\n", ovl_iocp->InternalHigh);
11125 ok(ovl_iocp->Internal == (ULONG)STATUS_CONNECTION_ABORTED || ovl_iocp->Internal == (ULONG)STATUS_LOCAL_DISCONNECT /* XP */, "got %#lx\n", ovl_iocp->Internal);
11126 }
11127
11128 bytes = 0xdeadbeef;
11129 key = 0xdeadbeef;
11130 ovl_iocp = (void *)0xdeadbeef;
11131 SetLastError(0xdeadbeef);
11132 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11133 ok(!ret, "got %d\n", ret);
11134 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11135 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11136 ok(key == 0xdeadbeef, "got key %#lx\n", key);
11137 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11138
11140
#define todo_wine
Definition: custom.c:79
#define STATUS_CONNECTION_ABORTED
Definition: ntstatus.h:709
#define STATUS_LOCAL_DISCONNECT
Definition: ntstatus.h:551
#define ERROR_CONNECTION_ABORTED
Definition: winerror.h:739
#define ERROR_NETNAME_DELETED
Definition: winerror.h:156

◆ iocp_async_read_thread()

static void iocp_async_read_thread ( SOCKET  src,
SOCKET  dst 
)
static

Definition at line 11382 of file sock.c.

11385{
11386 struct wsa_async_select_info select_info;
11387 struct wsa_recv_info recv_info;
11389 WSAOVERLAPPED *ovl_iocp;
11390 int ret;
11391 char data[512];
11392 DWORD bytes, tid;
11393 ULONG_PTR key;
11394 HWND hwnd;
11395 MSG msg;
11396
11397 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
11398 0, 0, 0, 0, NULL, NULL, 0, NULL);
11399 ok(hwnd != 0, "CreateWindowEx failed\n");
11400
11401 select_info.sock = src;
11402 select_info.hwnd = hwnd;
11403 thread = CreateThread(NULL, 0, wsa_async_select_thread, &select_info, 0, &tid);
11404 ok(thread != 0, "CreateThread error %u\n", GetLastError());
11405 ret = WaitForSingleObject(thread, 10000);
11406 ok(ret == WAIT_OBJECT_0, "thread failed to terminate\n");
11407
11408 Sleep(100);
11409 memset(&msg, 0, sizeof(msg));
11411 ok(ret, "got %d\n", ret);
11412 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11413 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11414 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11415 ok(msg.lParam == 2, "got %08lx\n", msg.lParam);
11416
11417 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
11418 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
11419
11420 Sleep(100);
11422 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11423
11424 memset(data, 0, sizeof(data));
11425 memset(&recv_info.ovl, 0, sizeof(recv_info.ovl));
11426 recv_info.sock = src;
11427 recv_info.wsa_buf.len = sizeof(data);
11428 recv_info.wsa_buf.buf = data;
11429 thread = CreateThread(NULL, 0, wsa_recv_thread, &recv_info, 0, &tid);
11430 ok(thread != 0, "CreateThread error %u\n", GetLastError());
11431 ret = WaitForSingleObject(thread, 10000);
11432 ok(ret == WAIT_OBJECT_0, "thread failed to terminate\n");
11433
11434 Sleep(100);
11436 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11437
11438 bytes = 0xdeadbeef;
11439 key = 0xdeadbeef;
11440 ovl_iocp = (void *)0xdeadbeef;
11441 SetLastError(0xdeadbeef);
11442 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11443 ok(!ret, "got %d\n", ret);
11445 if (GetLastError() == WAIT_TIMEOUT)
11446 {
11447 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11448 ok(key == 0xdeadbeef, "got key %lu\n", key);
11449 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11450 }
11451 else /* document XP behaviour */
11452 {
11453 ok(bytes == 0, "got bytes %u\n", bytes);
11454 ok(key == 0x12345678, "got key %#lx\n", key);
11455 ok(ovl_iocp == &recv_info.ovl, "got ovl %p\n", ovl_iocp);
11456 if (ovl_iocp)
11457 {
11458 ok(!ovl_iocp->InternalHigh, "got %#lx\n", ovl_iocp->InternalHigh);
11459 ok(ovl_iocp->Internal == STATUS_CANCELLED, "got %#lx\n", ovl_iocp->Internal);
11460 }
11461 }
11462
11463 Sleep(100);
11464 memset(&msg, 0, sizeof(msg));
11466 ok(!ret || broken(msg.hwnd == hwnd) /* XP */, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11467 if (ret) /* document XP behaviour */
11468 {
11469 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11470 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11471 ok(msg.lParam == 1, "got %08lx\n", msg.lParam);
11472 }
11473
11474 ret = send(dst, "Hello World!", 12, 0);
11475 ok(ret == 12, "send returned %d\n", ret);
11476
11477 Sleep(100);
11478 memset(&msg, 0, sizeof(msg));
11480 ok(!ret || broken(msg.hwnd == hwnd) /* XP */, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11481 if (ret) /* document XP behaviour */
11482 {
11483 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11484 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11485 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11486 ok(msg.lParam == 1, "got %08lx\n", msg.lParam);
11487 }
11488
11489 bytes = 0xdeadbeef;
11490 key = 0xdeadbeef;
11491 ovl_iocp = (void *)0xdeadbeef;
11492 SetLastError(0xdeadbeef);
11493 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11494 ok(ret || broken(GetLastError() == WAIT_TIMEOUT) /* XP */, "got %u\n", GetLastError());
11495 if (ret)
11496 {
11497 ok(bytes == 12, "got bytes %u\n", bytes);
11498 ok(key == 0x12345678, "got key %#lx\n", key);
11499 ok(ovl_iocp == &recv_info.ovl, "got ovl %p\n", ovl_iocp);
11500 if (ovl_iocp)
11501 {
11502 ok(ovl_iocp->InternalHigh == 12, "got %#lx\n", ovl_iocp->InternalHigh);
11503 ok(!ovl_iocp->Internal , "got %#lx\n", ovl_iocp->Internal);
11504 ok(!memcmp(data, "Hello World!", 12), "got %u bytes (%*s)\n", bytes, bytes, data);
11505 }
11506 }
11507 else /* document XP behaviour */
11508 {
11509 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11510 ok(key == 0xdeadbeef, "got key %lu\n", key);
11511 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11512 }
11513
11515
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:137
static TfClientId tid
static DWORD WINAPI wsa_recv_thread(void *param)
Definition: sock.c:11237
static DWORD WINAPI wsa_async_select_thread(void *param)
Definition: sock.c:11219
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define ERROR_OPERATION_ABORTED
Definition: winerror.h:575

◆ iocp_async_read_thread_closesocket()

static void iocp_async_read_thread_closesocket ( SOCKET  src)
static

Definition at line 11254 of file sock.c.

11257{
11258 struct wsa_async_select_info select_info;
11259 struct wsa_recv_info recv_info;
11261 WSAOVERLAPPED *ovl_iocp;
11262 int ret;
11263 char data[512];
11264 DWORD bytes, tid;
11265 ULONG_PTR key;
11266 HWND hwnd;
11267 MSG msg;
11268
11269 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
11270 0, 0, 0, 0, NULL, NULL, 0, NULL);
11271 ok(hwnd != 0, "CreateWindowEx failed\n");
11272
11273 select_info.sock = src;
11274 select_info.hwnd = hwnd;
11275 thread = CreateThread(NULL, 0, wsa_async_select_thread, &select_info, 0, &tid);
11276 ok(thread != 0, "CreateThread error %u\n", GetLastError());
11277 ret = WaitForSingleObject(thread, 10000);
11278 ok(ret == WAIT_OBJECT_0, "thread failed to terminate\n");
11279
11280 Sleep(100);
11281 memset(&msg, 0, sizeof(msg));
11283 ok(ret, "got %d\n", ret);
11284 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11285 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11286 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11287 ok(msg.lParam == 2, "got %08lx\n", msg.lParam);
11288
11289 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
11290 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
11291
11292 Sleep(100);
11294 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11295
11296 memset(data, 0, sizeof(data));
11297 memset(&recv_info.ovl, 0, sizeof(recv_info.ovl));
11298 recv_info.sock = src;
11299 recv_info.wsa_buf.len = sizeof(data);
11300 recv_info.wsa_buf.buf = data;
11301 thread = CreateThread(NULL, 0, wsa_recv_thread, &recv_info, 0, &tid);
11302 ok(thread != 0, "CreateThread error %u\n", GetLastError());
11303 ret = WaitForSingleObject(thread, 10000);
11304 ok(ret == WAIT_OBJECT_0, "thread failed to terminate\n");
11305
11306 Sleep(100);
11308 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11309
11310 bytes = 0xdeadbeef;
11311 key = 0xdeadbeef;
11312 ovl_iocp = (void *)0xdeadbeef;
11313 SetLastError(0xdeadbeef);
11314 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11315 ok(!ret, "got %d\n", ret);
11317 "got %u\n", GetLastError());
11318 if (GetLastError() == WAIT_TIMEOUT)
11319 {
11320 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11321 ok(key == 0xdeadbeef, "got key %lx\n", key);
11322 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11323 }
11324 else /* document XP behaviour */
11325 {
11326 ok(!bytes, "got bytes %u\n", bytes);
11327 ok(key == 0x12345678, "got key %#lx\n", key);
11328 ok(ovl_iocp == &recv_info.ovl, "got ovl %p\n", ovl_iocp);
11329 if (ovl_iocp)
11330 {
11331 ok(!ovl_iocp->InternalHigh, "got %#lx\n", ovl_iocp->InternalHigh);
11332 ok(ovl_iocp->Internal == STATUS_CANCELLED, "got %#lx\n", ovl_iocp->Internal);
11333 }
11334
11336 goto xp_is_broken;
11337 }
11338
11339 Sleep(100);
11341 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11342
11344
11345 Sleep(100);
11347 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11348
11349 bytes = 0xdeadbeef;
11350 key = 0xdeadbeef;
11351 ovl_iocp = NULL;
11352 SetLastError(0xdeadbeef);
11353 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11354 ok(!ret, "got %d\n", ret);
11357 ok(!bytes, "got bytes %u\n", bytes);
11358 ok(key == 0x12345678, "got key %#lx\n", key);
11359 ok(ovl_iocp == &recv_info.ovl, "got ovl %p\n", ovl_iocp);
11360 if (ovl_iocp)
11361 {
11362 ok(!ovl_iocp->InternalHigh, "got %#lx\n", ovl_iocp->InternalHigh);
11364 ok(ovl_iocp->Internal == (ULONG)STATUS_CONNECTION_ABORTED || ovl_iocp->Internal == (ULONG)STATUS_LOCAL_DISCONNECT /* XP */, "got %#lx\n", ovl_iocp->Internal);
11365 }
11366
11367xp_is_broken:
11368 bytes = 0xdeadbeef;
11369 key = 0xdeadbeef;
11370 ovl_iocp = (void *)0xdeadbeef;
11371 SetLastError(0xdeadbeef);
11372 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11373 ok(!ret, "got %d\n", ret);
11374 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11375 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11376 ok(key == 0xdeadbeef, "got key %lu\n", key);
11377 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11378
11380

◆ match_event_sequence()

static int match_event_sequence ( SOCKET  s,
WSANETWORKEVENTS netEvents,
const LPARAM seq 
)
static

Definition at line 5668 of file sock.c.

5671{
5672 int event, index, error, events;
5673 struct async_message *curr;
5674
5675 if (netEvents)
5676 {
5677 events = netEvents->lNetworkEvents;
5678 while (*seq)
5679 {
5680 event = WSAGETSELECTEVENT(*seq);
5681 error = WSAGETSELECTERROR(*seq);
5683
5684 if (!(events & event) && index != -1)
5685 return 0;
5686 if (events & event && index != -1)
5687 {
5688 if (netEvents->iErrorCode[index] != error)
5689 return 0;
5690 }
5691 events &= ~event;
5692 seq++;
5693 }
5694 if (events)
5695 return 0;
5696 }
5697 else
5698 {
5699 curr = messages_received;
5700 while (curr)
5701 {
5702 if (curr->socket == s)
5703 {
5704 if (!*seq) return 0;
5705 if (*seq != curr->lparam) return 0;
5706 seq++;
5707 }
5708 curr = curr->next;
5709 }
5710 if (*seq)
5711 return 0;
5712 }
HANDLE events[2]
Definition: event.c:4

Referenced by ok_event_sequence().

◆ NTSTATUS()

static NTSTATUS ( WINAPI pNtSetInformationFile)
static

◆ ok_event_sequence()

static void ok_event_sequence ( SOCKET  s,
HANDLE  hEvent,
const LPARAM seq,
const LPARAM **  broken_seqs,
int  completelyBroken 
)
static

Definition at line 5715 of file sock.c.

5718{
5719 MSG msg;
5720 WSANETWORKEVENTS events, *netEvents = NULL;
5721 int ret;
5722 DWORD dwRet;
5723
5725 {
5726 netEvents = &events;
5727
5728 dwRet = WaitForSingleObject(hEvent, 200);
5729 if (dwRet == WAIT_OBJECT_0)
5730 {
5731 ret = WSAEnumNetworkEvents(s, hEvent, netEvents);
5732 if (ret)
5733 {
5734 winetest_ok(0, "WSAEnumNetworkEvents failed, error %d\n", ret);
5735 return;
5736 }
5737 }
5738 else
5739 memset(netEvents, 0, sizeof(*netEvents));
5740 }
5741 else
5742 {
5743 Sleep(200);
5744 /* Run the message loop a little */
5745 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
5746 {
5748 }
5749 }
5750
5751 if (match_event_sequence(s, netEvents, seq))
5752 {
5753 winetest_ok(1, "Sequence matches expected: %s\n", dbgstr_event_seq(seq));
5755 return;
5756 }
5757
5758 if (broken_seqs)
5759 {
5760 for (; *broken_seqs; broken_seqs++)
5761 {
5762 if (match_event_sequence(s, netEvents, *broken_seqs))
5763 {
5764 winetest_ok(broken(1), "Sequence matches broken: %s, expected %s\n", dbgstr_event_seq_result(s, netEvents), dbgstr_event_seq(seq));
5766 return;
5767 }
5768 }
5769 }
5770
5771 winetest_ok(broken(completelyBroken), "Expected event sequence %s, got %s\n", dbgstr_event_seq(seq),
5772 dbgstr_event_seq_result(s, netEvents));
static void flush_events(void)
Definition: animate.c:39
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
static char * dbgstr_event_seq_result(SOCKET s, WSANETWORKEVENTS *netEvents)
Definition: sock.c:5584
static const char * dbgstr_event_seq(const LPARAM *seq)
Definition: sock.c:5565
static int match_event_sequence(SOCKET s, WSANETWORKEVENTS *netEvents, const LPARAM *seq)
Definition: sock.c:5668
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)

◆ oob_client()

static VOID WINAPI oob_client ( client_params par)
static

Definition at line 921 of file sock.c.

923{
924 test_params *gen = par->general;
926 int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
927
928 id = GetCurrentThreadId();
929 trace ( "oob_client (%x): starting\n", id );
930 /* wait here because we want to call set_so_opentype before creating a socket */
932 trace ( "oob_client (%x): server ready\n", id );
933
935 set_so_opentype ( FALSE ); /* non-overlapped */
936 client_start ( par );
937 mem = TlsGetValue ( tls );
938
939 /* Connect */
940 wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
941 0 ==, "oob_client (%x): connect error: %d\n" );
942 ok ( set_blocking ( mem->s, TRUE ) == 0,
943 "oob_client (%x): failed to set blocking mode\n", id );
944 trace ( "oob_client (%x) connected\n", id );
945
946 /* send data to server */
947 n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, 0, par->buflen );
948 ok ( n_sent == n_expected,
949 "oob_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
950
951 /* Receive data echoed back & check it */
952 n_recvd = do_synchronous_recv ( mem->s, mem->recv_buf, n_expected, 0, par->buflen );
953 ok ( n_recvd == n_expected,
954 "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
955 pos = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
956 ok ( pos == -1, "simple_client (%x): test pattern error: %d\n", id, pos);
957
958 /* send out-of-band data to server */
959 n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, MSG_OOB, par->buflen );
960 ok ( n_sent == n_expected,
961 "oob_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
962
963 /* shutdown send direction */
964 wsa_ok ( shutdown ( mem->s, SD_SEND ), 0 ==, "simple_client (%x): shutdown failed: %d\n" );
965
966 /* cleanup */
967 read_zero_bytes ( mem->s );
968 trace ( "oob_client (%x) exiting\n", id );
969 client_stop ();
GLuint id
Definition: glext.h:5910
static void read_zero_bytes(SOCKET s)
Definition: sock.c:384
static int do_synchronous_send(SOCKET s, char *buf, int buflen, int flags, int sendlen)
Definition: sock.c:393
static int set_blocking(SOCKET s, BOOL blocking)
Definition: sock.c:355
static void check_so_opentype(void)
Definition: sock.c:436
static void set_so_opentype(BOOL overlapped)
Definition: sock.c:342
static int do_synchronous_recv(SOCKET s, char *buf, int buflen, int flags, int recvlen)
Definition: sock.c:406
#define MSG_OOB
Definition: winsock.h:221

◆ oob_server()

static VOID WINAPI oob_server ( server_params par)
static

Definition at line 663 of file sock.c.

665{
666 test_params *gen = par->general;
668 u_long atmark = 0;
669 int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, tmp,
670 id = GetCurrentThreadId();
671
672 trace ( "oob_server (%x) starting\n", id );
673
674 set_so_opentype ( FALSE ); /* non-overlapped */
675 server_start ( par );
676 mem = TlsGetValue ( tls );
677
678 wsa_ok ( set_blocking ( mem->s, TRUE ), 0 ==, "oob_server (%x): failed to set blocking mode: %d\n");
679 wsa_ok ( listen ( mem->s, SOMAXCONN ), 0 ==, "oob_server (%x): listen failed: %d\n");
680
681 trace ( "oob_server (%x) ready\n", id );
682 SetEvent ( server_ready ); /* notify clients */
683
684 trace ( "oob_server (%x): waiting for client\n", id );
685
686 /* accept a single connection */
687 tmp = sizeof ( mem->sock[0].peer );
688 mem->sock[0].s = accept ( mem->s, (struct sockaddr*) &mem->sock[0].peer, &tmp );
689 wsa_ok ( mem->sock[0].s, INVALID_SOCKET !=, "oob_server (%x): accept failed: %d\n" );
690
691 ok ( mem->sock[0].peer.sin_addr.s_addr == inet_addr ( gen->inet_addr ),
692 "oob_server (%x): strange peer address\n", id );
693
694 /* check initial atmark state */
695 ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
696 ok ( atmark == 1, "oob_server (%x): unexpectedly at the OOB mark: %i\n", id, atmark );
697
698 /* Receive normal data */
699 n_recvd = do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
700 ok ( n_recvd == n_expected,
701 "oob_server (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
702 pos = test_buffer ( mem->sock[0].buf, gen->chunk_size, gen->n_chunks );
703 ok ( pos == -1, "oob_server (%x): test pattern error: %d\n", id, pos);
704
705 /* check atmark state */
706 ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
707 ok ( atmark == 1, "oob_server (%x): unexpectedly at the OOB mark: %i\n", id, atmark );
708
709 /* Echo data back */
710 n_sent = do_synchronous_send ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
711 ok ( n_sent == n_expected,
712 "oob_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
713
714 /* Receive a part of the out-of-band data and print atmark state */
715 n_recvd = do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, 8, 0, par->buflen );
716 ok ( n_recvd == 8,
717 "oob_server (%x): received less data than expected: %d of %d\n", id, n_recvd, 8 );
718 n_expected -= 8;
719
720 ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
721 trace( "oob_server (%x): %s the OOB mark: %i\n", id, atmark == 1 ? "not at" : "at", atmark );
722
723 /* Receive the rest of the out-of-band data and check atmark state */
724 do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
725
726 ioctlsocket ( mem->sock[0].s, SIOCATMARK, &atmark );
727 todo_wine ok ( atmark == 0, "oob_server (%x): not at the OOB mark: %i\n", id, atmark );
728
729 /* cleanup */
730 wsa_ok ( closesocket ( mem->sock[0].s ), 0 ==, "oob_server (%x): closesocket error: %d\n" );
731 mem->sock[0].s = INVALID_SOCKET;
732
733 trace ( "oob_server (%x) exiting\n", id );
734 server_stop ();
unsigned long u_long
Definition: linux.h:269
#define ioctlsocket
Definition: ncftp.h:481
static void server_stop(void)
Definition: sock.c:548
static void server_start(server_params *par)
Definition: sock.c:521
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
test_params * general
Definition: sock.c:140
int buflen
Definition: sock.c:142
#define SOMAXCONN
Definition: winsock.h:399
#define SIOCATMARK
Definition: winsock.h:253

◆ PCSTR()

static PCSTR ( WINAPI pInetNtop)
static

◆ PCWSTR()

static PCWSTR ( WINAPI pInetNtopW)
static

◆ poll_isset()

static BOOL poll_isset ( WSAPOLLFD *  fds,
int  max,
SOCKET  s,
int  rev 
)
static

Definition at line 7114 of file sock.c.

7114 {fds[ix].fd = s; fds[ix++].events = ev;}
7115#define POLL_ISSET(s, rev) poll_isset(fds, ix, s, rev)
7116static BOOL poll_isset(WSAPOLLFD *fds, int max, SOCKET s, int rev)
7117{
7118 int k;
7119 for (k = 0; k < max; k++)
7120 if (fds[k].fd == s && (fds[k].revents == rev)) return TRUE;
int rev
Definition: sort.c:17
static int fd
Definition: io.c:51
static BOOL poll_isset(WSAPOLLFD *fds, int max, SOCKET s, int rev)
Definition: sock.c:7114
#define max(a, b)
Definition: svc.c:63

◆ read_zero_bytes()

static void read_zero_bytes ( SOCKET  s)
static

Definition at line 384 of file sock.c.

386{
387 char buf[256];
388 int tmp, n = 0;
389 while ( ( tmp = recv ( s, buf, 256, 0 ) ) > 0 )
390 n += tmp;
391 ok ( n <= 0, "garbage data received: %d bytes\n", n );

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

◆ recv_thread()

static DWORD WINAPI recv_thread ( LPVOID  arg)
static

Definition at line 6720 of file sock.c.

6723{
6724 SOCKET sock = *(SOCKET *)arg;
6725 char buffer[32];
6726 WSABUF wsa;
6727 WSAOVERLAPPED ov;
6728 DWORD flags = 0;
6729
6730 wsa.buf = buffer;
6731 wsa.len = sizeof(buffer);
6732 ov.hEvent = WSACreateEvent();
6733 WSARecv(sock, &wsa, 1, NULL, &flags, &ov, NULL);
6734
6735 WaitForSingleObject(ov.hEvent, 1000);
ULONG len
Definition: ws2def.h:519
CHAR FAR * buf
Definition: ws2def.h:520
WSAEVENT hEvent
Definition: winsock2.h:613

◆ select_server()

static VOID WINAPI select_server ( server_params par)
static

Definition at line 739 of file sock.c.

741{
742 test_params *gen = par->general;
744 int n_expected = gen->n_chunks * gen->chunk_size, tmp, i,
745 id = GetCurrentThreadId(), n_connections = 0, n_sent, n_recvd,
746 n_set, delta, n_ready;
747 struct timeval timeout = {0,10}; /* wait for 10 milliseconds */
748 fd_set fds_recv, fds_send, fds_openrecv, fds_opensend;
749
750 trace ( "select_server (%x) starting\n", id );
751
752 set_so_opentype ( FALSE ); /* non-overlapped */
753 server_start ( par );
754 mem = TlsGetValue ( tls );
755
756 wsa_ok ( set_blocking ( mem->s, FALSE ), 0 ==, "select_server (%x): failed to set blocking mode: %d\n");
757 wsa_ok ( listen ( mem->s, SOMAXCONN ), 0 ==, "select_server (%x): listen failed: %d\n");
758
759 trace ( "select_server (%x) ready\n", id );
760 SetEvent ( server_ready ); /* notify clients */
761
762 FD_ZERO ( &fds_openrecv );
763 FD_ZERO ( &fds_recv );
764 FD_ZERO ( &fds_send );
765 FD_ZERO ( &fds_opensend );
766
767 FD_SET ( mem->s, &fds_openrecv );
768
769 while(1)
770 {
771 fds_recv = fds_openrecv;
772 fds_send = fds_opensend;
773
774 n_set = 0;
775
776 wsa_ok ( ( n_ready = select ( 0, &fds_recv, &fds_send, NULL, &timeout ) ), SOCKET_ERROR !=,
777 "select_server (%x): select() failed: %d\n" );
778
779 /* check for incoming requests */
780 if ( FD_ISSET ( mem->s, &fds_recv ) ) {
781 n_set += 1;
782
783 trace ( "select_server (%x): accepting client connection\n", id );
784
785 /* accept a single connection */
786 tmp = sizeof ( mem->sock[n_connections].peer );
787 mem->sock[n_connections].s = accept ( mem->s, (struct sockaddr*) &mem->sock[n_connections].peer, &tmp );
788 wsa_ok ( mem->sock[n_connections].s, INVALID_SOCKET !=, "select_server (%x): accept() failed: %d\n" );
789
790 ok ( mem->sock[n_connections].peer.sin_addr.s_addr == inet_addr ( gen->inet_addr ),
791 "select_server (%x): strange peer address\n", id );
792
793 /* add to list of open connections */
794 FD_SET ( mem->sock[n_connections].s, &fds_openrecv );
795 FD_SET ( mem->sock[n_connections].s, &fds_opensend );
796
797 n_connections++;
798 }
799
800 /* handle open requests */
801
802 for ( i = 0; i < n_connections; i++ )
803 {
804 if ( FD_ISSET( mem->sock[i].s, &fds_recv ) ) {
805 n_set += 1;
806
807 if ( mem->sock[i].n_recvd < n_expected ) {
808 /* Receive data & check it */
809 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 );
810 ok ( n_recvd != SOCKET_ERROR, "select_server (%x): error in recv(): %d\n", id, WSAGetLastError() );
811 mem->sock[i].n_recvd += n_recvd;
812
813 if ( mem->sock[i].n_recvd == n_expected ) {
814 int pos = test_buffer ( mem->sock[i].buf, gen->chunk_size, gen->n_chunks );
815 ok ( pos == -1, "select_server (%x): test pattern error: %d\n", id, pos );
816 FD_CLR ( mem->sock[i].s, &fds_openrecv );
817 }
818
819 ok ( mem->sock[i].n_recvd <= n_expected, "select_server (%x): received too many bytes: %d\n", id, mem->sock[i].n_recvd );
820 }
821 }
822
823 /* only echo back what we've received */
824 delta = mem->sock[i].n_recvd - mem->sock[i].n_sent;
825
826 if ( FD_ISSET ( mem->sock[i].s, &fds_send ) ) {
827 n_set += 1;
828
829 if ( ( delta > 0 ) && ( mem->sock[i].n_sent < n_expected ) ) {
830 /* Echo data back */
831 n_sent = send ( mem->sock[i].s, mem->sock[i].buf + mem->sock[i].n_sent, min ( delta, par->buflen ), 0 );
832 ok ( n_sent != SOCKET_ERROR, "select_server (%x): error in send(): %d\n", id, WSAGetLastError() );
833 mem->sock[i].n_sent += n_sent;
834
835 if ( mem->sock[i].n_sent == n_expected ) {
836 FD_CLR ( mem->sock[i].s, &fds_opensend );
837 }
838
839 ok ( mem->sock[i].n_sent <= n_expected, "select_server (%x): sent too many bytes: %d\n", id, mem->sock[i].n_sent );
840 }
841 }
842 }
843
844 /* check that select returned the correct number of ready sockets */
845 ok ( ( n_set == n_ready ), "select_server (%x): select() returns wrong number of ready sockets\n", id );
846
847 /* check if all clients are done */
848 if ( ( fds_opensend.fd_count == 0 )
849 && ( fds_openrecv.fd_count == 1 ) /* initial socket that accepts clients */
850 && ( n_connections == min ( gen->n_clients, MAX_CLIENTS ) ) ) {
851 break;
852 }
853 }
854
855 for ( i = 0; i < min ( gen->n_clients, MAX_CLIENTS ); i++ )
856 {
857 /* cleanup */
858 read_zero_bytes ( mem->sock[i].s );
859 wsa_ok ( closesocket ( mem->sock[i].s ), 0 ==, "select_server (%x): closesocket error: %d\n" );
860 mem->sock[i].s = INVALID_SOCKET;
861 }
862
863 trace ( "select_server (%x) exiting\n", id );
864 server_stop ();
u_int fd_count
Definition: winsock.h:67
Definition: dhcpd.h:245
#define FD_ISSET(fd, set)
Definition: winsock.h:100
#define FD_CLR(fd, set)
Definition: winsock.h:74

◆ SelectCloseThread()

static DWORD WINAPI SelectCloseThread ( void param)
static

Definition at line 3648 of file sock.c.

3651{
3652 SOCKET s = *(SOCKET*)param;
3653 Sleep(500);
3654 closesocket(s);

Referenced by test_select().

◆ SelectReadThread()

static DWORD WINAPI SelectReadThread ( void param)
static

Definition at line 3621 of file sock.c.

3624{
3626 fd_set readfds;
3627 int ret;
3628 struct sockaddr_in addr;
3629 struct timeval select_timeout;
3630
3631 memset(&readfds, 0, sizeof(readfds));
3632 FD_ZERO(&readfds);
3633 FD_SET(par->s, &readfds);
3634 select_timeout.tv_sec=5;
3635 select_timeout.tv_usec=0;
3636 addr.sin_family = AF_INET;
3637 addr.sin_addr.s_addr = inet_addr(SERVERIP);
3638 addr.sin_port = htons(SERVERPORT);
3639
3640 do_bind(par->s, (struct sockaddr *)&addr, sizeof(addr));
3641 wsa_ok(listen(par->s, SOMAXCONN ), 0 ==, "SelectReadThread (%x): listen failed: %d\n");
3642
3644 ret = select(par->s+1, &readfds, NULL, NULL, &select_timeout);
3645 par->ReadKilled = (ret == 1);
3646
static void do_bind(SOCKET s, struct sockaddr *addr, int addrlen)
Definition: sock.c:507

Referenced by test_select().

◆ server_start()

static void server_start ( server_params par)
static

Definition at line 521 of file sock.c.

523{
524 int i;
525 test_params *gen = par->general;
526 server_memory *mem = LocalAlloc ( LPTR, sizeof ( server_memory ) );
527
528 TlsSetValue ( tls, mem );
529 mem->s = WSASocketA ( AF_INET, gen->sock_type, gen->sock_prot,
530 NULL, 0, par->sock_flags );
531 ok ( mem->s != INVALID_SOCKET, "Server: WSASocket failed\n" );
532
533 mem->addr.sin_family = AF_INET;
534 mem->addr.sin_addr.s_addr = inet_addr ( gen->inet_addr );
535 mem->addr.sin_port = htons ( gen->inet_port );
536
537 for (i = 0; i < MAX_CLIENTS; i++)
538 {
539 mem->sock[i].s = INVALID_SOCKET;
540 mem->sock[i].buf = LocalAlloc ( LPTR, gen->n_chunks * gen->chunk_size );
541 mem->sock[i].n_recvd = 0;
542 mem->sock[i].n_sent = 0;
543 }
544
545 if ( gen->sock_type == SOCK_STREAM )
546 do_bind ( mem->s, (struct sockaddr*) &mem->addr, sizeof (mem->addr) );
DWORD sock_flags
Definition: sock.c:141

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

◆ server_stop()

static void server_stop ( void  )
static

Definition at line 548 of file sock.c.

550{
551 int i;
553
554 for (i = 0; i < MAX_CLIENTS; i++ )
555 {
556 LocalFree ( mem->sock[i].buf );
557 if ( mem->sock[i].s != INVALID_SOCKET )
558 closesocket ( mem->sock[i].s );
559 }
560 ok ( closesocket ( mem->s ) == 0, "closesocket failed\n" );
561 LocalFree ( mem );

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

◆ set_blocking()

static int set_blocking ( SOCKET  s,
BOOL  blocking 
)
static

Definition at line 355 of file sock.c.

357{
358 u_long val = !blocking;
359 return ioctlsocket ( s, FIONBIO, &val );
GLuint GLfloat * val
Definition: glext.h:7180
#define FIONBIO
Definition: winsock.h:149

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

◆ set_so_opentype()

static void set_so_opentype ( BOOL  overlapped)
static

Definition at line 342 of file sock.c.

344{
345 int optval = !overlapped, newval, len = sizeof (int);
346
348 (LPVOID) &optval, sizeof (optval) ) == 0,
349 "setting SO_OPENTYPE failed\n" );
351 (LPVOID) &newval, &len ) == 0,
352 "getting SO_OPENTYPE failed\n" );
353 ok ( optval == newval, "failed to set SO_OPENTYPE\n" );
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:81
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421

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

◆ setup_connector_socket()

static SOCKET setup_connector_socket ( struct sockaddr_in addr,
int  len,
BOOL  nonblock 
)
static

Definition at line 4227 of file sock.c.

4230{
4231 int ret;
4232 SOCKET connector;
4233
4234 connector = socket(AF_INET, SOCK_STREAM, 0);
4235 ok(connector != INVALID_SOCKET, "failed to create connector socket %d\n", WSAGetLastError());
4236
4237 if (nonblock)
4238 set_blocking(connector, !nonblock);
4239
4240 ret = connect(connector, (struct sockaddr *)addr, len);
4241 if (!nonblock)
4242 ok(!ret, "connecting to accepting socket failed %d\n", WSAGetLastError());
4243 else if (ret == SOCKET_ERROR)
4244 {
4247 "expected 10035 or 10036, got %d\n", error);
4248 }
4249
static int nonblock(int fd, int isnonblock)
Definition: adnsresfilter.c:86
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define WSAEINPROGRESS
Definition: winerror.h:1949

Referenced by test_select().

◆ setup_iocp_src()

static SOCKET setup_iocp_src ( struct sockaddr_in bindAddress)
static

Definition at line 9608 of file sock.c.

9611{
9613 int iret, socklen;
9614
9616 if (src == INVALID_SOCKET)
9617 {
9618 skip("could not create listener socket, error %d\n", WSAGetLastError());
9619 goto end;
9620 }
9621
9622 memset(bindAddress, 0, sizeof(*bindAddress));
9623 bindAddress->sin_family = AF_INET;
9624 bindAddress->sin_addr.s_addr = inet_addr("127.0.0.1");
9625 iret = bind(src, (struct sockaddr*)bindAddress, sizeof(*bindAddress));
9626 if (iret != 0)
9627 {
9628 skip("failed to bind, error %d\n", WSAGetLastError());
9629 goto end;
9630 }
9631
9632 socklen = sizeof(*bindAddress);
9633 iret = getsockname(src, (struct sockaddr*)bindAddress, &socklen);
9634 if (iret != 0) {
9635 skip("failed to lookup bind address, error %d\n", WSAGetLastError());
9636 goto end;
9637 }
9638
9639 if (set_blocking(src, FALSE))
9640 {
9641 skip("couldn't make socket non-blocking, error %d\n", WSAGetLastError());
9642 goto end;
9643 }
9644
9645 iret = listen(src, 5);
9646 if (iret != 0)
9647 {
9648 skip("listening failed, errno = %d\n", WSAGetLastError());
9649 goto end;
9650 }
9651
9652 ret = src;
9653end:
9654 if (src != ret && ret == INVALID_SOCKET)
#define skip(...)
Definition: atltest.h:64
GLuint GLuint end
Definition: gl.h:1545
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213
struct in_addr sin_addr
Definition: winsock.h:512
short sin_family
Definition: winsock.h:510

◆ setup_server_socket()

static SOCKET setup_server_socket ( struct sockaddr_in addr,
int len 
)
static

Definition at line 4181 of file sock.c.

4184{
4185 int ret, val;
4187
4190 {
4191 trace("error creating server socket: %d\n", WSAGetLastError());
4192 return INVALID_SOCKET;
4193 }
4194
4195 val = 1;
4196 ret = setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
4197 if (ret)
4198 {
4199 trace("error setting SO_REUSEADDR: %d\n", WSAGetLastError());
4201 return INVALID_SOCKET;
4202 }
4203
4204 ret = bind(server_socket, (struct sockaddr *)addr, *len);
4205 if (ret)
4206 {
4207 trace("error binding server socket: %d\n", WSAGetLastError());
4208 }
4209
4211 if (ret)
4212 {
4213 skip("failed to lookup bind address: %d\n", WSAGetLastError());
4215 return INVALID_SOCKET;
4216 }
4217
4218 ret = listen(server_socket, 5);
4219 if (ret)
4220 {
4221 trace("error making server socket listen: %d\n", WSAGetLastError());
4223 return INVALID_SOCKET;
4224 }
4225
static int server_socket
Definition: notification.c:641
#define SO_REUSEADDR
Definition: winsock.h:180

Referenced by test_select().

◆ simple_client()

static VOID WINAPI simple_client ( client_params par)
static

Definition at line 871 of file sock.c.

873{
874 test_params *gen = par->general;
876 int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
877
878 id = GetCurrentThreadId();
879 trace ( "simple_client (%x): starting\n", id );
880 /* wait here because we want to call set_so_opentype before creating a socket */
882 trace ( "simple_client (%x): server ready\n", id );
883
885 set_so_opentype ( FALSE ); /* non-overlapped */
886 client_start ( par );
887 mem = TlsGetValue ( tls );
888
889 /* Connect */
890 wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
891 0 ==, "simple_client (%x): connect error: %d\n" );
892 ok ( set_blocking ( mem->s, TRUE ) == 0,
893 "simple_client (%x): failed to set blocking mode\n", id );
894 trace ( "simple_client (%x) connected\n", id );
895
896 /* send data to server */
897 n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, 0, par->buflen );
898 ok ( n_sent == n_expected,
899 "simple_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 /* Receive data echoed back & check it */
905 n_recvd = do_synchronous_recv ( mem->s, mem->recv_buf, n_expected, 0, par->buflen );
906 ok ( n_recvd == n_expected,
907 "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
908
909 /* check data */
910 pos = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
911 ok ( pos == -1, "simple_client (%x): test pattern error: %d\n", id, pos);
912
913 /* cleanup */
914 read_zero_bytes ( mem->s );
915 trace ( "simple_client (%x) exiting\n", id );
916 client_stop ();

◆ simple_mixed_client()

static VOID WINAPI simple_mixed_client ( client_params par)
static

Definition at line 974 of file sock.c.

976{
977 test_params *gen = par->general;
979 int pos, n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
980 int fromLen = sizeof(mem->addr);
981 struct sockaddr test;
982
983 id = GetCurrentThreadId();
984 trace ( "simple_client (%x): starting\n", id );
985 /* wait here because we want to call set_so_opentype before creating a socket */
987 trace ( "simple_client (%x): server ready\n", id );
988
990 set_so_opentype ( FALSE ); /* non-overlapped */
991 client_start ( par );
992 mem = TlsGetValue ( tls );
993
994 /* Connect */
995 wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
996 0 ==, "simple_client (%x): connect error: %d\n" );
997 ok ( set_blocking ( mem->s, TRUE ) == 0,
998 "simple_client (%x): failed to set blocking mode\n", id );
999 trace ( "simple_client (%x) connected\n", id );
1000
1001 /* send data to server */
1002 n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, 0, par->buflen );
1003 ok ( n_sent == n_expected,
1004 "simple_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
1005
1006 /* shutdown send direction */
1007 wsa_ok ( shutdown ( mem->s, SD_SEND ), 0 ==, "simple_client (%x): shutdown failed: %d\n" );
1008
1009 /* this shouldn't change, since lpFrom, is not updated on
1010 connection oriented sockets - exposed by bug 11640
1011 */
1012 ((struct sockaddr_in*)&test)->sin_addr.s_addr = inet_addr("0.0.0.0");
1013
1014 /* Receive data echoed back & check it */
1015 n_recvd = do_synchronous_recvfrom ( mem->s,
1016 mem->recv_buf,
1017 n_expected,
1018 0,
1019 (struct sockaddr *)&test,
1020 &fromLen,
1021 par->buflen );
1022 ok ( n_recvd == n_expected,
1023 "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
1024
1025 /* check that lpFrom was not updated */
1026 ok(0 ==
1027 strcmp(
1028 inet_ntoa(((struct sockaddr_in*)&test)->sin_addr),
1029 "0.0.0.0"), "lpFrom shouldn't be updated on connection oriented sockets\n");
1030
1031 /* check data */
1032 pos = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
1033 ok ( pos == -1, "simple_client (%x): test pattern error: %d\n", id, pos);
1034
1035 /* cleanup */
1036 read_zero_bytes ( mem->s );
1037 trace ( "simple_client (%x) exiting\n", id );
1038 client_stop ();
static int do_synchronous_recvfrom(SOCKET s, char *buf, int buflen, int flags, struct sockaddr *from, int *fromlen, int recvlen)
Definition: sock.c:419

◆ simple_server()

static VOID WINAPI simple_server ( server_params par)
static

Definition at line 607 of file sock.c.

609{
610 test_params *gen = par->general;
612 int pos, n_recvd, n_sent, n_expected = gen->n_chunks * gen->chunk_size, tmp, i,
613 id = GetCurrentThreadId();
614
615 trace ( "simple_server (%x) starting\n", id );
616
617 set_so_opentype ( FALSE ); /* non-overlapped */
618 server_start ( par );
619 mem = TlsGetValue ( tls );
620
621 wsa_ok ( set_blocking ( mem->s, TRUE ), 0 ==, "simple_server (%x): failed to set blocking mode: %d\n");
622 wsa_ok ( listen ( mem->s, SOMAXCONN ), 0 ==, "simple_server (%x): listen failed: %d\n");
623
624 trace ( "simple_server (%x) ready\n", id );
625 SetEvent ( server_ready ); /* notify clients */
626
627 for ( i = 0; i < min ( gen->n_clients, MAX_CLIENTS ); i++ )
628 {
629 trace ( "simple_server (%x): waiting for client\n", id );
630
631 /* accept a single connection */
632 tmp = sizeof ( mem->sock[0].peer );
633 mem->sock[0].s = accept ( mem->s, (struct sockaddr*) &mem->sock[0].peer, &tmp );
634 wsa_ok ( mem->sock[0].s, INVALID_SOCKET !=, "simple_server (%x): accept failed: %d\n" );
635
636 ok ( mem->sock[0].peer.sin_addr.s_addr == inet_addr ( gen->inet_addr ),
637 "simple_server (%x): strange peer address\n", id );
638
639 /* Receive data & check it */
640 n_recvd = do_synchronous_recv ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
641 ok ( n_recvd == n_expected,
642 "simple_server (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
643 pos = test_buffer ( mem->sock[0].buf, gen->chunk_size, gen->n_chunks );
644 ok ( pos == -1, "simple_server (%x): test pattern error: %d\n", id, pos);
645
646 /* Echo data back */
647 n_sent = do_synchronous_send ( mem->sock[0].s, mem->sock[0].buf, n_expected, 0, par->buflen );
648 ok ( n_sent == n_expected,
649 "simple_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
650
651 /* cleanup */
652 read_zero_bytes ( mem->sock[0].s );
653 wsa_ok ( closesocket ( mem->sock[0].s ), 0 ==, "simple_server (%x): closesocket error: %d\n" );
654 mem->sock[0].s = INVALID_SOCKET;
655 }
656
657 trace ( "simple_server (%x) exiting\n", id );
658 server_stop ();

◆ START_TEST()

START_TEST ( sock  )

Definition at line 11554 of file sock.c.

11557{
11558 int i;
11559
11560/* Leave these tests at the beginning. They depend on WSAStartup not having been
11561 * called, which is done by Init() below. */
11564
11565 Init();
11566
11573
11574 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
11575 {
11576 trace ( " **** STARTING TEST %d ****\n", i );
11577 do_test ( &tests[i] );
11578 trace ( " **** TEST %d COMPLETE ****\n", i );
11579 }
11580
11581 test_UDP();
11582
11587
11590
11593
11594 test_errors();
11595 test_listen();
11596 test_select();
11597 test_accept();
11603 test_dns();
11607
11610 test_WSARecv();
11611 test_WSAPoll();
11613 test_iocp();
11614
11615 test_events(0);
11616 test_events(1);
11617
11618 test_ipv6only();
11623 test_AcceptEx();
11626
11629
11633
11636
11639
11640 /* this is an io heavy test, do it at the end so the kernel doesn't start dropping packets */
11641 test_send();
11643
static void do_test(void)
Definition: ftrandom.c:516
static void test_events(void)
Definition: itemdlg.c:1172
static void test_WSAAddressToStringW(void)
Definition: sock.c:3191
static void test_WithWSAStartup(void)
Definition: sock.c:1185
static void test_WSAAsyncGetServByName(void)
Definition: sock.c:9574
static void test_send(void)
Definition: sock.c:5354
static void test_WSAStringToAddressA(void)
Definition: sock.c:3359
static void test_UDP(void)
Definition: sock.c:2299
static void test_GetAddrInfoExW(void)
Definition: sock.c:7613
static void test_inet_pton(void)
Definition: sock.c:5003
static void test_getpeername(void)
Definition: sock.c:9087
static void test_write_watch(void)
Definition: sock.c:6971
static void test_gethostbyname_hack(void)
Definition: sock.c:4774
static void test_WSADuplicateSocket(void)
Definition: sock.c:2795
static void test_TransmitFile(void)
Definition: sock.c:8854
static void test_WSAStringToAddressW(void)
Definition: sock.c:3483
static void test_ipv6only(void)
Definition: sock.c:6347
static void test_GetAddrInfoW(void)
Definition: sock.c:7332
static void Init(void)
Definition: sock.c:1287
static void test_synchronous_WSAIoctl(void)
Definition: sock.c:9461
static void test_inet_ntoa(void)
Definition: sock.c:10558
static void test_dns(void)
Definition: sock.c:4621
static void test_WSAEnumNetworkEvents(void)
Definition: sock.c:2956
static void test_completion_port(void)
Definition: sock.c:9657
static void test_gethostbyname(void)
Definition: sock.c:4677
static void test_listen(void)
Definition: sock.c:3693
static void test_WithoutWSAStartup(void)
Definition: sock.c:1170
static void test_so_reuseaddr(void)
Definition: sock.c:1924
static void test_getsockname(void)
Definition: sock.c:4530
static void test_WSAPoll(void)
Definition: sock.c:7122
static void test_WSAEnumNameSpaceProvidersW(void)
Definition: sock.c:10832
static void test_select(void)
Definition: sock.c:3780
static void test_accept(void)
Definition: sock.c:4251
static void test_inet_addr(void)
Definition: sock.c:4864
static void test_iocp(void)
Definition: sock.c:11517
static void test_DisconnectEx(void)
Definition: sock.c:8732
static void test_WSAEnumNameSpaceProvidersA(void)
Definition: sock.c:10747
static void test_WSARecv(void)
Definition: sock.c:6745
static void test_WSASocket(void)
Definition: sock.c:2409
static void test_ioctlsocket(void)
Definition: sock.c:5148
static void test_set_getsockopt(void)
Definition: sock.c:1408
static void test_WSAAddressToStringA(void)
Definition: sock.c:3029
static void test_WSALookupService(void)
Definition: sock.c:10586
static void test_ip_pktinfo(void)
Definition: sock.c:2003
static test_setup tests[]
Definition: sock.c:2190
static void test_errors(void)
Definition: sock.c:3656
static void test_sioAddressListChange(void)
Definition: sock.c:9225
static void test_getaddrinfo(void)
Definition: sock.c:7728
static void test_WSASendTo(void)
Definition: sock.c:6681
static void test_AcceptEx(void)
Definition: sock.c:8224
static void test_getservbyname(void)
Definition: sock.c:2388
static void test_gethostname(void)
Definition: sock.c:4831
static void test_extendedSocketOptions(void)
Definition: sock.c:4413
static void test_addr_to_print(void)
Definition: sock.c:4872
static void test_ConnectEx(void)
Definition: sock.c:8013
static void test_address_list_query(void)
Definition: sock.c:10484
static void test_WSASendMsg(void)
Definition: sock.c:6496
static void test_WSAAsyncGetServByPort(void)
Definition: sock.c:9544
static void test_sioRoutingInterfaceQuery(void)
Definition: sock.c:9177

◆ StartClients()

static void StartClients ( LPTHREAD_START_ROUTINE  routine,
test_params general,
client_params par 
)
static

Definition at line 1347 of file sock.c.

1350{
1351 int i;
1352 par->general = general;
1353 for ( i = 1; i <= min ( general->n_clients, MAX_CLIENTS ); i++ )
1354 {
1355 client_id = i - 1;
1356 thread[i] = CreateThread ( NULL, 0, routine, par, 0, &thread_id[i] );
1357 ok ( thread[i] != NULL, "Failed to create client thread\n" );
1358 /* Make sure the client is up and running */
1360 };
int jpeg_marker_parser_method routine
Definition: jpeglib.h:1093

Referenced by do_test().

◆ StartServer()

static void StartServer ( LPTHREAD_START_ROUTINE  routine,
test_params general,
server_params par 
)
static

Definition at line 1339 of file sock.c.

1342{
1343 par->general = general;
1344 thread[0] = CreateThread ( NULL, 0, routine, par, 0, &thread_id[0] );
1345 ok ( thread[0] != NULL, "Failed to create server thread\n" );

Referenced by do_test().

◆ sync_read()

static void sync_read ( SOCKET  src,
SOCKET  dst 
)
static

Definition at line 10917 of file sock.c.

10920{
10921 int ret;
10922 char data[512];
10923
10924 ret = send(dst, "Hello World!", 12, 0);
10925 ok(ret == 12, "send returned %d\n", ret);
10926
10927 memset(data, 0, sizeof(data));
10928 ret = recv(src, data, sizeof(data), 0);
10929 ok(ret == 12, "expected 12, got %d\n", ret);

◆ tcp_socketpair()

static int tcp_socketpair ( SOCKET src,
SOCKET dst 
)
static

Definition at line 241 of file sock.c.

243{
245 struct sockaddr_in addr;
246 int len;
247 int ret;
248
251
253 if (*src == INVALID_SOCKET)
254 goto end;
255
257 if (server == INVALID_SOCKET)
258 goto end;
259
260 memset(&addr, 0, sizeof(addr));
261 addr.sin_family = AF_INET;
262 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
263 ret = bind(server, (struct sockaddr*)&addr, sizeof(addr));
264 if (ret != 0)
265 goto end;
266
267 len = sizeof(addr);
268 ret = getsockname(server, (struct sockaddr*)&addr, &len);
269 if (ret != 0)
270 goto end;
271
272 ret = listen(server, 1);
273 if (ret != 0)
274 goto end;
275
276 ret = connect(*src, (struct sockaddr*)&addr, sizeof(addr));
277 if (ret != 0)
278 goto end;
279
280 len = sizeof(addr);
281 *dst = accept(server, (struct sockaddr*)&addr, &len);
282
283end:
284 if (server != INVALID_SOCKET)
286 if (*src != INVALID_SOCKET && *dst != INVALID_SOCKET)
287 return 0;
290 return -1;
#define IPPROTO_TCP
Definition: ip.h:196
static rfbScreenInfoPtr server
Definition: vnc.c:74

Referenced by test_select(), and test_WithWSAStartup().

◆ tcp_socketpair_ovl()

static int tcp_socketpair_ovl ( SOCKET src,
SOCKET dst 
)
static

Definition at line 292 of file sock.c.

294{
296 struct sockaddr_in addr;
297 int len, ret;
298
301
303 if (*src == INVALID_SOCKET)
304 goto end;
305
307 if (server == INVALID_SOCKET)
308 goto end;
309
310 memset(&addr, 0, sizeof(addr));
311 addr.sin_family = AF_INET;
312 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
313 ret = bind(server, (struct sockaddr *)&addr, sizeof(addr));
314 if (ret != 0)
315 goto end;
316
317 len = sizeof(addr);
318 ret = getsockname(server, (struct sockaddr *)&addr, &len);
319 if (ret != 0)
320 goto end;
321
322 ret = listen(server, 1);
323 if (ret != 0)
324 goto end;
325
326 ret = connect(*src, (struct sockaddr *)&addr, sizeof(addr));
327 if (ret != 0)
328 goto end;
329
330 len = sizeof(addr);
331 *dst = accept(server, (struct sockaddr *)&addr, &len);
332
333end:
334 if (server != INVALID_SOCKET)
336 if (*src != INVALID_SOCKET && *dst != INVALID_SOCKET)
337 return 0;
340 return -1;
SOCKET WSAAPI WSASocketW(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags)
Definition: socklife.c:490
#define WSA_FLAG_OVERLAPPED
Definition: winsock2.h:466

◆ test_accept()

static void test_accept ( void  )
static

Definition at line 4251 of file sock.c.

4254{
4255 int ret;
4257 struct sockaddr_in address;
4258 SOCKADDR_STORAGE ss, ss_empty;
4259 int socklen;
4260 select_thread_params thread_params;
4261 HANDLE thread_handle = NULL;
4262 DWORD id;
4263
4264 memset(&address, 0, sizeof(address));
4265 address.sin_addr.s_addr = inet_addr("127.0.0.1");
4266 address.sin_family = AF_INET;
4267
4268 socklen = sizeof(address);
4271 {
4272 trace("error creating server socket: %d\n", WSAGetLastError());
4273 return;
4274 }
4275
4276 connector = setup_connector_socket(&address, socklen, FALSE);
4277 if (connector == INVALID_SOCKET) goto done;
4278
4279 trace("Blocking accept next\n");
4280
4282 ok(accepted == INVALID_SOCKET && WSAGetLastError() == WSATRY_AGAIN, "Failed to defer connection, %d\n", WSAGetLastError());
4283
4285 ok(accepted != INVALID_SOCKET, "Failed to accept deferred connection, error %d\n", WSAGetLastError());
4286
4289 {
4290 trace("error creating event: %d\n", GetLastError());
4291 goto done;
4292 }
4293
4294 thread_params.s = server_socket;
4295 thread_params.ReadKilled = FALSE;
4296 thread_handle = CreateThread(NULL, 0, AcceptKillThread, &thread_params, 0, &id);
4297 if (thread_handle == NULL)
4298 {
4299 trace("error creating thread: %d\n", GetLastError());
4300 goto done;
4301 }
4302
4304 Sleep(200);
4306 if (ret != 0)
4307 {
4308 trace("closesocket failed: %d\n", WSAGetLastError());
4309 goto done;
4310 }
4311
4312 WaitForSingleObject(thread_handle, 1000);
4313 ok(thread_params.ReadKilled, "closesocket did not wake up accept\n");
4314
4316 closesocket(connector);
4317 accepted = connector = INVALID_SOCKET;
4318
4319 socklen = sizeof(address);
4321 if (server_socket == INVALID_SOCKET) goto done;
4322
4323 connector =