-
- _GSocket_Configure_Callbacks(socket);
-}
-
-
-/* Internals */
-
-void _GSocket_Configure_Callbacks(GSocket *socket)
-{
- long mask = 0;
- int count;
-
- for (count = 0; count < GSOCK_MAX_EVENT; count++)
- {
- if (socket->m_cbacks[count] != NULL)
- {
- switch (count)
- {
- case GSOCK_INPUT: mask |= FD_READ; break;
- case GSOCK_OUTPUT: mask |= FD_WRITE; break;
- case GSOCK_CONNECTION: mask |= (FD_ACCEPT | FD_CONNECT); break;
- case GSOCK_LOST: mask |= FD_CLOSE; break;
- }
- }
- }
-
- WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, mask);
-}
-
-LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
-{
- GSocket *socket;
- GSocketEvent event;
- GSocketCallback cback;
-
- if (uMsg >= WM_USER && uMsg <= (WM_USER + MAXSOCKETS - 1))
- {
- EnterCriticalSection(&critical);
- socket = socketList[(uMsg - WM_USER)];
- event = -1;
- cback = NULL;
-
- /* Check that the socket still exists (it has not been
- * destroyed) and for safety, check that the m_fd field
- * is what we expect it to be.
- */
- if ((socket != NULL) && (socket->m_fd == wParam))
- {
- switch WSAGETSELECTEVENT(lParam)
- {
- case FD_READ: event = GSOCK_INPUT; break;
- case FD_WRITE: event = GSOCK_OUTPUT; break;
- case FD_ACCEPT: event = GSOCK_CONNECTION; break;
- case FD_CONNECT:
- {
- if (WSAGETSELECTERROR(lParam) != 0)
- event = GSOCK_LOST;
- else
- event = GSOCK_CONNECTION;
- break;
- }
- case FD_CLOSE: event = GSOCK_LOST; break;
- }
-
- if (event != -1)
- cback = socket->m_cbacks[event];
- }
-
- /* OK, we can now leave the critical section because we have
- * already obtained the callback address (we make no further
- * accesses to socket->whatever)
- */
- LeaveCriticalSection(&critical);
-
- if (cback != NULL)
- (cback)(socket, event, socket->m_data[event]);
-
- return (LRESULT) 0;
- }
- else
- return DefWindowProc(hWnd, uMsg, wParam, lParam);