-
-/* Internals */
-
-/* _GSocket_Enable_Events:
- * Enable all event notifications; we need to be notified of all
- * events for internal processing, but we will only notify users
- * when an appropiate callback function has been installed.
- */
-void _GSocket_Enable_Events(GSocket *socket)
-{
- assert (socket != NULL);
-
- if (socket->m_fd != INVALID_SOCKET)
- {
- WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber,
- FD_READ | FD_WRITE | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
- }
-}
-
-/* _GSocket_Disable_Events:
- * Disable event notifications (when shutdowning the socket)
- */
-void _GSocket_Disable_Events(GSocket *socket)
-{
- assert (socket != NULL);
-
- if (socket->m_fd != INVALID_SOCKET)
- {
- WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, 0);
- }
-}
-
-
-LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
-{
- GSocket *socket;
- GSocketEvent event;
- GSocketCallback cback;
- char *data;
-
- if (uMsg >= WM_USER && uMsg <= (WM_USER + MAXSOCKETS - 1))
- {
- EnterCriticalSection(&critical);
- socket = socketList[(uMsg - WM_USER)];
- event = -1;
- cback = NULL;
- data = 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];
- data = socket->m_data[event];
-
- if (event == GSOCK_LOST)
- socket->m_detected = GSOCK_LOST_FLAG;
- else
- socket->m_detected |= (1 << 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). However, the app should
- * be prepared to handle events from a socket that has just
- * been closed!
- */
- LeaveCriticalSection(&critical);
-
- if (cback != NULL)
- (cback)(socket, event, data);
-
- return (LRESULT) 0;
- }
- else
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
-}
-