ReactOS 0.4.15-dev-8119-g4fb2fdb
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 8837 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 7120 of file sock.c.

◆ POLL_ISSET

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

Definition at line 7122 of file sock.c.

◆ POLL_SET

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

Definition at line 7121 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 9503 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);
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4242
#define wine_dbgstr_w
Definition: kernel32.h:34

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

8842{
8843 char buf1[256], buf2[256];
8844 BOOL success;
8845 int i = 0;
8846
8848 while (1)
8849 {
8850 DWORD n1 = 0, n2 = 0;
8851
8852 success = ReadFile(handle, buf1, sizeof(buf1), &n1, NULL);
8853 ok_(file,line)(success, "Failed to read from file.\n");
8854 if (success && n1 == 0)
8855 break;
8856 else if(!success)
8857 return;
8858 n2 = recv(sock, buf2, n1, 0);
8859 ok_(file,line)(n1 == n2, "Block %d size mismatch (%d != %d)\n", i, n1, n2);
8860 ok_(file,line)(memcmp(buf1, buf2, n2) == 0, "Block %d failed\n", i);
8861 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:147
int n1
Definition: dwarfget.c:147
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 9504 of file sock.c.

9507{
9508 static const char class_name[] = "ws2_32 async message window class";
9509
9510 WNDCLASSEXA wndclass;
9511 HWND hWnd;
9512
9513 wndclass.cbSize = sizeof(wndclass);
9514 wndclass.style = CS_HREDRAW | CS_VREDRAW;
9515 wndclass.lpfnWndProc = DefWindowProcA;
9516 wndclass.cbClsExtra = 0;
9517 wndclass.cbWndExtra = 0;
9518 wndclass.hInstance = GetModuleHandleA(NULL);
9521 wndclass.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
9522 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
9523 wndclass.lpszClassName = class_name;
9524 wndclass.lpszMenuName = NULL;
9525
9526 RegisterClassExA(&wndclass);
9527
9528 hWnd = CreateWindowA(class_name, "ws2_32 async message window", WS_OVERLAPPEDWINDOW,
9529 0, 0, 500, 500, NULL, NULL, GetModuleHandleA(NULL), NULL);
9530 if (!hWnd)
9531 {
9532 ok(0, "failed to create window: %u\n", GetLastError());
9533 return NULL;
9534 }
9535
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:3204
HINSTANCE hInstance
Definition: winuser.h:3206
HCURSOR hCursor
Definition: winuser.h:3208
LPCSTR lpszMenuName
Definition: winuser.h:3210
HICON hIconSm
Definition: winuser.h:3212
UINT style
Definition: winuser.h:3202
int cbWndExtra
Definition: winuser.h:3205
UINT cbSize
Definition: winuser.h:3201
WNDPROC lpfnWndProc
Definition: winuser.h:3203
LPCSTR lpszClassName
Definition: winuser.h:3211
HICON hIcon
Definition: winuser.h:3207
HBRUSH hbrBackground
Definition: winuser.h:3209
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CS_VREDRAW
Definition: winuser.h:658
#define COLOR_WINDOW
Definition: winuser.h:918
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:4315
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define IDI_APPLICATION
Definition: winuser.h:704
ATOM WINAPI RegisterClassExA(_In_ CONST WNDCLASSEXA *)
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE hInstance, _In_ LPCSTR lpIconName)
Definition: cursoricon.c:2091
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2121
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
static UINT UINT last
Definition: font.c:45

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(), _Function_class_(), _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(), IntFixUpDevModeNames(), KiNmiInterruptHandler(), LdrpCreateDllSection(), CSettings::Load(), load_truetype_glyph(), main(), MapAnsiQuerySetToUnicode(), MapUnicodeQuerySetToAnsi(), MiDoMappedCopy(), MiDoPoolCopy(), MmMapViewOfSection(), MmPapAllocatePagesInRange(), NtAreMappedFilesTheSame(), NtGdiExtEscape(), NtGdiGetFontUnicodeRanges(), NtGdiGetGlyphOutline(), NtGdiSelectClipPath(), NtGdiSetDIBitsToDeviceInternal(), NtGdiSetPixelFormat(), NtGdiSwapBuffers(), NtSetSystemPowerState(), NtStopProfile(), NtUserAttachThreadInput(), NtUserBuildPropList(), NtUserCallHwndLock(), NtUserCallHwndParamLock(), NtUserCallNextHookEx(), NtUserCloseDesktop(), NtUserCopyAcceleratorTable(), NtUserCreateAcceleratorTable(), NtUserCreateCaret(), NtUserCreateDesktop(), NtUserDeferWindowPos(), NtUserDefSetText(), NtUserDestroyMenu(), NtUserDragDetect(), NtUserDrawCaptionTemp(), NtUserDrawMenuBarTemp(), NtUserFillWindow(), NtUserFindWindowEx(), NtUserFlashWindowEx(), NtUserGetClipCursor(), NtUserGetComboBoxInfo(), NtUserGetDCEx(), NtUserGetGuiResources(), NtUserGetGUIThreadInfo(), NtUserGetInternalWindowPos(), NtUserGetLayeredWindowAttributes(), NtUserGetListBoxInfo(), NtUserGetMenuIndex(), NtUserGetMenuItemRect(), NtUserGetObjectInformation(), NtUserGetScrollBarInfo(), NtUserGetSystemMenu(), NtUserGetUpdateRect(), NtUserGetWindowPlacement(), NtUserHideCaret(), NtUserHiliteMenuItem(), NtUserInternalGetWindowText(), NtUserMenuItemFromPoint(), NtUserMinMaximize(), NtUserPrintWindow(), NtUserQueryWindow(), NtUserRedrawWindow(), NtUserRegisterWindowMessage(), NtUserRemoveProp(), NtUserSBGetParms(), NtUserScrollDC(), NtUserSetActiveWindow(), NtUserSetCursorIconData(), NtUserSetFocus(), NtUserSetInternalWindowPos(), NtUserSetLayeredWindowAttributes(), NtUserSetMenu(), NtUserSetProp(), NtUserSetShellWindowEx(), NtUserSetSystemCursor(), NtUserSetSystemMenu(), NtUserSetWindowFNID(), NtUserSetWindowPlacement(), NtUserSetWindowPos(), NtUserSetWindowRgn(), NtUserSetWindowWord(), NtUserShowCaret(), NtUserShowWindow(), NtUserShowWindowAsync(), NtUserSwitchDesktop(), NtUserTrackPopupMenuEx(), NtUserUnhookWindowsHookEx(), NtUserUpdateLayeredWindow(), NtUserValidateHandleSecure(), 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(), RegOpenKeyExW(), RegReplaceKeyA(), RtlGetNtProductType(), RtlpLookupDynamicFunctionEntry(), RtlVirtualUnwind(), SetDIBitsToDevice(), sfnt_load_face(), SRomFindMasterAdapter(), SRomRegisterMasterAdapter(), 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 10550 of file sock.c.

10553{
10554 ULONG addr;
10555 const char *str;
10556 HANDLE *event = param;
10557
10558 addr = inet_addr("4.3.2.1");
10559 ok(addr == htonl(0x04030201), "expected 0x04030201, got %08x\n", addr);
10560 str = inet_ntoa(*(struct in_addr *)&addr);
10561 ok(!strcmp(str, "4.3.2.1"), "expected 4.3.2.1, got %s\n", str);
10562
10563 SetEvent(event[0]);
10564 WaitForSingleObject(event[1], 3000);
10565
#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 11151 of file sock.c.

11154{
11155 HANDLE port;
11156 WSAOVERLAPPED *ovl_iocp;
11157 int ret;
11158 DWORD bytes;
11159 ULONG_PTR key;
11160 HWND hwnd;
11161 MSG msg;
11162
11163 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
11164 0, 0, 0, 0, NULL, NULL, 0, NULL);
11165 ok(hwnd != 0, "CreateWindowEx failed\n");
11166
11168 ok(!ret, "got %d\n", ret);
11169
11170 Sleep(100);
11171 memset(&msg, 0, sizeof(msg));
11173 ok(ret, "got %d\n", ret);
11174 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11175 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11176 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11177 ok(msg.lParam == 2, "got %08lx\n", msg.lParam);
11178
11179 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
11180 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
11181
11182 Sleep(100);
11184 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11185
11186 bytes = 0xdeadbeef;
11187 key = 0xdeadbeef;
11188 ovl_iocp = (void *)0xdeadbeef;
11189 SetLastError(0xdeadbeef);
11190 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11191 ok(!ret, "got %d\n", ret);
11192 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11193 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11194 ok(key == 0xdeadbeef, "got key %lu\n", key);
11195 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11196
11197 Sleep(100);
11199 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11200
11202
11203 Sleep(100);
11204 memset(&msg, 0, sizeof(msg));
11206 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11207
11208 bytes = 0xdeadbeef;
11209 key = 0xdeadbeef;
11210 ovl_iocp = (void *)0xdeadbeef;
11211 SetLastError(0xdeadbeef);
11212 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11213 ok(!ret, "got %d\n", ret);
11214 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11215 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11216 ok(key == 0xdeadbeef, "got key %lu\n", key);
11217 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11218
11220
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:1196
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 10940 of file sock.c.

10943{
10944 HANDLE port;
10945 WSAOVERLAPPED ovl, *ovl_iocp;
10946 WSABUF buf;
10947 int ret;
10948 char data[512];
10949 DWORD flags, bytes;
10950 ULONG_PTR key;
10951
10952 memset(data, 0, sizeof(data));
10953 memset(&ovl, 0, sizeof(ovl));
10954
10955 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
10956 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
10957
10958 buf.len = sizeof(data);
10959 buf.buf = data;
10960 bytes = 0xdeadbeef;
10961 flags = 0;
10962 SetLastError(0xdeadbeef);
10963 ret = WSARecv(src, &buf, 1, &bytes, &flags, &ovl, NULL);
10964 ok(ret == SOCKET_ERROR, "got %d\n", ret);
10965 ok(GetLastError() == ERROR_IO_PENDING, "got %u\n", GetLastError());
10966 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
10967
10968 bytes = 0xdeadbeef;
10969 key = 0xdeadbeef;
10970 ovl_iocp = (void *)0xdeadbeef;
10971 SetLastError(0xdeadbeef);
10972 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
10973 ok(!ret, "got %d\n", ret);
10974 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
10975 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
10976 ok(key == 0xdeadbeef, "got key %#lx\n", key);
10977 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
10978
10979 ret = send(dst, "Hello World!", 12, 0);
10980 ok(ret == 12, "send returned %d\n", ret);
10981
10982 bytes = 0xdeadbeef;
10983 key = 0xdeadbeef;
10984 ovl_iocp = NULL;
10985 SetLastError(0xdeadbeef);
10986 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
10987 ok(ret, "got %d\n", ret);
10988 ok(bytes == 12, "got bytes %u\n", bytes);
10989 ok(key == 0x12345678, "got key %#lx\n", key);
10990 ok(ovl_iocp == &ovl, "got ovl %p\n", ovl_iocp);
10991 if (ovl_iocp)
10992 {
10993 ok(ovl_iocp->InternalHigh == 12, "got %#lx\n", ovl_iocp->InternalHigh);
10994 ok(!ovl_iocp->Internal , "got %#lx\n", ovl_iocp->Internal);
10995 ok(!memcmp(data, "Hello World!", 12), "got %u bytes (%*s)\n", bytes, bytes, data);
10996 }
10997
10998 bytes = 0xdeadbeef;
10999 key = 0xdeadbeef;
11000 ovl_iocp = (void *)0xdeadbeef;
11001 SetLastError(0xdeadbeef);
11002 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11003 ok(!ret, "got %d\n", ret);
11004 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11005 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11006 ok(key == 0xdeadbeef, "got key %#lx\n", key);
11007 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11008
#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 11010 of file sock.c.

11013{
11014 HANDLE port;
11015 WSAOVERLAPPED ovl, *ovl_iocp;
11016 WSABUF buf;
11017 int ret;
11018 char data[512];
11019 DWORD flags, bytes;
11020 ULONG_PTR key;
11021 HWND hwnd;
11022 MSG msg;
11023
11024 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
11025 0, 0, 0, 0, NULL, NULL, 0, NULL);
11026 ok(hwnd != 0, "CreateWindowEx failed\n");
11027
11029 ok(!ret, "got %d\n", ret);
11030
11031 Sleep(100);
11032 memset(&msg, 0, sizeof(msg));
11034 ok(ret, "got %d\n", ret);
11035 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11036 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11037 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11038 ok(msg.lParam == 2, "got %08lx\n", msg.lParam);
11039
11040 memset(data, 0, sizeof(data));
11041 memset(&ovl, 0, sizeof(ovl));
11042
11043 port = CreateIoCompletionPort((HANDLE)src, 0, 0x12345678, 0);
11044 ok(port != 0, "CreateIoCompletionPort error %u\n", GetLastError());
11045
11046 Sleep(100);
11048 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11049
11050 buf.len = sizeof(data);
11051 buf.buf = data;
11052 bytes = 0xdeadbeef;
11053 flags = 0;
11054 SetLastError(0xdeadbeef);
11055 ret = WSARecv(src, &buf, 1, &bytes, &flags, &ovl, NULL);
11056 ok(ret == SOCKET_ERROR, "got %d\n", ret);
11057 ok(GetLastError() == ERROR_IO_PENDING, "got %u\n", GetLastError());
11058 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11059
11060 Sleep(100);
11062 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11063
11064 bytes = 0xdeadbeef;
11065 key = 0xdeadbeef;
11066 ovl_iocp = (void *)0xdeadbeef;
11067 SetLastError(0xdeadbeef);
11068 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11069 ok(!ret, "got %d\n", ret);
11070 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11071 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11072 ok(key == 0xdeadbeef, "got key %#lx\n", key);
11073 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11074
11075 Sleep(100);
11077 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11078
11079 switch (how_to_close)
11080 {
11081 case 0:
11083 break;
11084 case 1:
11086 break;
11087 case 2:
11088 pNtClose((HANDLE)src);
11089 break;
11090 default:
11091 ok(0, "wrong value %d\n", how_to_close);
11092 break;
11093 }
11094
11095 Sleep(200);
11096 memset(&msg, 0, sizeof(msg));
11098 switch (how_to_close)
11099 {
11100 case 0:
11101 ok(!ret, "got %04x,%08lx,%08lx\n", msg.message, msg.wParam, msg.lParam);
11102 break;
11103 case 1:
11104 case 2:
11106{
11107 ok(ret, "got %d\n", ret);
11108 ok(msg.hwnd == hwnd, "got %p\n", msg.hwnd);
11109 ok(msg.message == WM_SOCKET, "got %04x\n", msg.message);
11110 ok(msg.wParam == src, "got %08lx\n", msg.wParam);
11111 ok(msg.lParam == 0x20, "got %08lx\n", msg.lParam);
11112}
11113 break;
11114 default:
11115 ok(0, "wrong value %d\n", how_to_close);
11116 break;
11117 }
11118
11119 bytes = 0xdeadbeef;
11120 key = 0xdeadbeef;
11121 ovl_iocp = NULL;
11122 SetLastError(0xdeadbeef);
11123 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11124 ok(!ret, "got %d\n", ret);
11127 ok(!bytes, "got bytes %u\n", bytes);
11128 ok(key == 0x12345678, "got key %#lx\n", key);
11129 ok(ovl_iocp == &ovl, "got ovl %p\n", ovl_iocp);
11130 if (ovl_iocp)
11131 {
11132 ok(!ovl_iocp->InternalHigh, "got %#lx\n", ovl_iocp->InternalHigh);
11134 ok(ovl_iocp->Internal == (ULONG)STATUS_CONNECTION_ABORTED || ovl_iocp->Internal == (ULONG)STATUS_LOCAL_DISCONNECT /* XP */, "got %#lx\n", ovl_iocp->Internal);
11135 }
11136
11137 bytes = 0xdeadbeef;
11138 key = 0xdeadbeef;
11139 ovl_iocp = (void *)0xdeadbeef;
11140 SetLastError(0xdeadbeef);
11141 ret = GetQueuedCompletionStatus(port, &bytes, &key, &ovl_iocp, 100);
11142 ok(!ret, "got %d\n", ret);
11143 ok(GetLastError() == WAIT_TIMEOUT, "got %u\n", GetLastError());
11144 ok(bytes == 0xdeadbeef, "got bytes %u\n", bytes);
11145 ok(key == 0xdeadbeef, "got key %#lx\n", key);
11146 ok(!ovl_iocp, "got ovl %p\n", ovl_iocp);
11147
11149
#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 11391 of file sock.c.

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

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

◆ 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: SystemMenu.c:167
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 7123 of file sock.c.

7123 {fds[ix].fd = s; fds[ix++].events = ev;}
7124#define POLL_ISSET(s, rev) poll_isset(fds, ix, s, rev)
7125static BOOL poll_isset(WSAPOLLFD *fds, int max, SOCKET s, int rev)
7126{
7127 int k;
7128 for (k = 0; k < max; k++)
7129 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:7123
#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 9617 of file sock.c.

9620{
9622 int iret, socklen;
9623
9625 if (src == INVALID_SOCKET)
9626 {
9627 skip("could not create listener socket, error %d\n", WSAGetLastError());
9628 goto end;
9629 }
9630
9631 memset(bindAddress, 0, sizeof(*bindAddress));
9632 bindAddress->sin_family = AF_INET;
9633 bindAddress->sin_addr.s_addr = inet_addr("127.0.0.1");
9634 iret = bind(src, (struct sockaddr*)bindAddress, sizeof(*bindAddress));
9635 if (iret != 0)
9636 {
9637 skip("failed to bind, error %d\n", WSAGetLastError());
9638 goto end;
9639 }
9640
9641 socklen = sizeof(*bindAddress);
9642 iret = getsockname(src, (struct sockaddr*)bindAddress, &socklen);
9643 if (iret != 0) {
9644 skip("failed to lookup bind address, error %d\n", WSAGetLastError());
9645 goto end;
9646 }
9647
9648 if (set_blocking(src, FALSE))
9649 {
9650 skip("couldn't make socket non-blocking, error %d\n", WSAGetLastError());
9651 goto end;
9652 }
9653
9654 iret = listen(src, 5);
9655 if (iret != 0)
9656 {
9657 skip("listening failed, errno = %d\n", WSAGetLastError());
9658 goto end;
9659 }
9660
9661 ret = src;
9662end:
9663 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 11563 of file sock.c.

11566{
11567 int i;
11568
11569/* Leave these tests at the beginning. They depend on WSAStartup not having been
11570 * called, which is done by Init() below. */
11573
11574 Init();
11575
11582
11583 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
11584 {
11585 trace ( " **** STARTING TEST %d ****\n", i );
11586 do_test ( &tests[i] );
11587 trace ( " **** TEST %d COMPLETE ****\n", i );
11588 }
11589
11590 test_UDP();
11591
11596
11599
11602
11603 test_errors();
11604 test_listen();
11605 test_select();
11606 test_accept();
11612 test_dns();
11616
11619 test_WSARecv();
11620 test_WSAPoll();
11622 test_iocp();
11623
11624 test_events(0);
11625 test_events(1);
11626
11627 test_ipv6only();
11632
11633#ifdef __REACTOS__
11635 {
11636 skip("WSPAcceptEx(), WSPConnectEx() and WSPDisconnectEx() are UNIMPLEMENTED on ReactOS\n");
11637 skip("Skipping tests due to hang. See ROSTESTS-385\n");
11638 }
11639 else
11640 {
11641#endif
11642 test_AcceptEx();
11645#ifdef __REACTOS__
11646 }
11647#endif
11648
11651
11655
11658
11661
11662 /* this is an io heavy test, do it at the end so the kernel doesn't start dropping packets */
11663 test_send();
11665
static void do_test(void)
Definition: ftrandom.c:516
static void test_events(void)
Definition: itemdlg.c:1172
int winetest_interactive
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:9583
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:7622
static void test_inet_pton(void)
Definition: sock.c:5003
static void test_getpeername(void)
Definition: sock.c:9096
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:8863
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:7341
static void Init(void)
Definition: sock.c:1287
static void test_synchronous_WSAIoctl(void)
Definition: sock.c:9470
static void test_inet_ntoa(void)
Definition: sock.c:10567
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:9666
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:7131
static void test_WSAEnumNameSpaceProvidersW(void)
Definition: sock.c:10841
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:11526
static void test_DisconnectEx(void)
Definition: sock.c:8741
static void test_WSAEnumNameSpaceProvidersA(void)
Definition: sock.c:10756
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:10595
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:9234
static void test_getaddrinfo(void)
Definition: sock.c:7737
static void test_WSASendTo(void)
Definition: sock.c:6681
static void test_AcceptEx(void)
Definition: sock.c:8233
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:8022
static void test_address_list_query(void)
Definition: sock.c:10493
static void test_WSASendMsg(void)
Definition: sock.c:6496
static void test_WSAAsyncGetServByPort(void)
Definition: sock.c:9553
static void test_sioRoutingInterfaceQuery(void)
Definition: sock.c:9186

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

10929{
10930 int ret;
10931 char data[512];
10932
10933 ret = send(dst, "Hello World!", 12, 0);
10934 ok(ret == 12, "send returned %d\n", ret);
10935
10936 memset(data, 0, sizeof(data));
10937 ret = recv(src, data, sizeof(data), 0);
10938 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