From c0035396caef1365e0bb52974c192191e33a2af2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 11 Jul 2012 14:22:18 +0000 Subject: [PATCH] -dos2unix --- src/util/network.c | 154 ++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/src/util/network.c b/src/util/network.c index f550c18b2..c61704be9 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -1130,37 +1130,37 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) } #if MINGW -struct _select_params -{ - fd_set *r; - fd_set *w; - fd_set *e; - struct timeval *tv; - HANDLE wakeup; - HANDLE standby; - SOCKET wakeup_socket; - int status; -}; - -static DWORD WINAPI -_selector (LPVOID p) -{ - struct _select_params *sp = p; - int i; - while (1) - { - WaitForSingleObject (sp->standby, INFINITE); - ResetEvent (sp->standby); - sp->status = select (1, sp->r, sp->w, sp->e, sp->tv); - if (FD_ISSET (sp->wakeup_socket, sp->r)) - { - FD_CLR (sp->wakeup_socket, sp->r); - sp->status -= 1; - } - SetEvent (sp->wakeup); - } - return 0; -} +struct _select_params +{ + fd_set *r; + fd_set *w; + fd_set *e; + struct timeval *tv; + HANDLE wakeup; + HANDLE standby; + SOCKET wakeup_socket; + int status; +}; + +static DWORD WINAPI +_selector (LPVOID p) +{ + struct _select_params *sp = p; + int i; + while (1) + { + WaitForSingleObject (sp->standby, INFINITE); + ResetEvent (sp->standby); + sp->status = select (1, sp->r, sp->w, sp->e, sp->tv); + if (FD_ISSET (sp->wakeup_socket, sp->r)) + { + FD_CLR (sp->wakeup_socket, sp->r); + sp->status -= 1; + } + SetEvent (sp->wakeup); + } + return 0; +} #endif /** @@ -1193,14 +1193,14 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, static HANDLE hEventPipeWrite = 0; static HANDLE hEventReadReady = 0; - static struct _select_params sp; + static struct _select_params sp; static HANDLE select_thread = NULL; static HANDLE select_finished_event = NULL; static HANDLE select_standby_event = NULL; - static SOCKET select_wakeup_socket = -1; - static SOCKET select_send_socket = -1; + static SOCKET select_wakeup_socket = -1; + static SOCKET select_send_socket = -1; static struct timeval select_timeout; - + int readPipes = 0; int writePipePos = 0; @@ -1313,46 +1313,46 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, if (select_thread == NULL) { - SOCKET select_listening_socket = -1; - struct sockaddr_in s_in; - int alen; - int res; - unsigned long p; - - select_standby_event = CreateEvent (NULL, TRUE, FALSE, NULL); - select_finished_event = CreateEvent (NULL, TRUE, FALSE, NULL); - - select_wakeup_socket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); - - select_listening_socket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); - - p = 1; - res = ioctlsocket (select_wakeup_socket, FIONBIO, &p); - - alen = sizeof (s_in); - s_in.sin_family = AF_INET; - s_in.sin_port = 0; - s_in.sin_addr.S_un.S_un_b.s_b1 = 127; - s_in.sin_addr.S_un.S_un_b.s_b2 = 0; - s_in.sin_addr.S_un.S_un_b.s_b3 = 0; - s_in.sin_addr.S_un.S_un_b.s_b4 = 1; - res = bind (select_listening_socket, (const struct sockaddr *) &s_in, sizeof (s_in)); - - res = getsockname (select_listening_socket, (struct sockaddr *) &s_in, &alen); - - res = listen (select_listening_socket, SOMAXCONN); - - res = connect (select_wakeup_socket, (const struct sockaddr *) &s_in, sizeof (s_in)); - - select_send_socket = accept (select_listening_socket, (struct sockaddr *) &s_in, &alen); - - closesocket (select_listening_socket); - - sp.wakeup = select_finished_event; - sp.standby = select_standby_event; + SOCKET select_listening_socket = -1; + struct sockaddr_in s_in; + int alen; + int res; + unsigned long p; + + select_standby_event = CreateEvent (NULL, TRUE, FALSE, NULL); + select_finished_event = CreateEvent (NULL, TRUE, FALSE, NULL); + + select_wakeup_socket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); + + select_listening_socket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); + + p = 1; + res = ioctlsocket (select_wakeup_socket, FIONBIO, &p); + + alen = sizeof (s_in); + s_in.sin_family = AF_INET; + s_in.sin_port = 0; + s_in.sin_addr.S_un.S_un_b.s_b1 = 127; + s_in.sin_addr.S_un.S_un_b.s_b2 = 0; + s_in.sin_addr.S_un.S_un_b.s_b3 = 0; + s_in.sin_addr.S_un.S_un_b.s_b4 = 1; + res = bind (select_listening_socket, (const struct sockaddr *) &s_in, sizeof (s_in)); + + res = getsockname (select_listening_socket, (struct sockaddr *) &s_in, &alen); + + res = listen (select_listening_socket, SOMAXCONN); + + res = connect (select_wakeup_socket, (const struct sockaddr *) &s_in, sizeof (s_in)); + + select_send_socket = accept (select_listening_socket, (struct sockaddr *) &s_in, &alen); + + closesocket (select_listening_socket); + + sp.wakeup = select_finished_event; + sp.standby = select_standby_event; sp.wakeup_socket = select_wakeup_socket; - - select_thread = CreateThread (NULL, 0, _selector, &sp, 0, NULL); + + select_thread = CreateThread (NULL, 0, _selector, &sp, 0, NULL); } /* Events for pipes */ @@ -1534,14 +1534,14 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, * and wake up by itself. */ if (ms_total != 0) - i = send (select_send_socket, (const char *) &returnedpos, 1, 0); - i = (int) WaitForSingleObject (select_finished_event, INFINITE); + i = send (select_send_socket, (const char *) &returnedpos, 1, 0); + i = (int) WaitForSingleObject (select_finished_event, INFINITE); LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished waiting for the select thread: %d %d\n", i, sp.status); if (ms_total != 0) { do { - i = recv (select_wakeup_socket, (char *) &returnedpos, 1, 0); + i = recv (select_wakeup_socket, (char *) &returnedpos, 1, 0); } while (i == 1); } /* Check aexcept, add its contents to awrite */ -- 2.25.1