LONG CALLBACK _mio_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LONG lParam) { if(msg == WM_TIMER) { return 1; } else if(msg >= WM_MIO_EVENT) { mio_priv_t m = (mio_priv_t)(GetWindowLongPtr(hwnd, GWLP_USERDATA)); if(msg - WM_MIO_EVENT >= m->count) { mio_debug(ZONE, "mio event %d on socket id %d out of socket bounds %d", WSAGETSELECTEVENT(lParam), msg - WM_MIO_EVENT, m->count); return 0; } if(!m->fds[msg - WM_MIO_EVENT].event & WSAGETSELECTEVENT(lParam)) { mio_debug(ZONE, "unmatched mio event %d on socket #%d", WSAGETSELECTEVENT(lParam), m->fds[msg - WM_MIO_EVENT].mio_fd.fd); return 0; } m->select_fd = &m->fds[msg - WM_MIO_EVENT]; m->select_fd->revent = WSAGETSELECTEVENT(lParam); mio_debug(ZONE, "get mio event %d on socket #%d", m->select_fd->revent, m->select_fd->mio_fd.fd); \ return 1; } else if(msg == WM_CREATE) { SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams); } else { return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
void OnWSANetEvent(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) { int rc; char szTemp[256]; szTemp[0]=0; SOCKET sock = (SOCKET) wParam; if(WSAGETSELECTEVENT(lParam) == FD_READ) { int acc_sin_len = sizeof(acc_sin); getpeername(sock,(LPSOCKADDR) &acc_sin,(int FAR*) &acc_sin_len); rc = recv(sock,szTemp,256,0); szTemp[rc]=0; if(rc) SendReply(hWnd,sock,szTemp); //closesocket(sock); } else if(WSAGETSELECTEVENT(lParam)==FD_CLOSE) { int acc_sin_len = sizeof(acc_sin); getpeername(sock,(LPSOCKADDR) &acc_sin,(int FAR*) &acc_sin_len); TCHAR wtmp[255]; wsprintf(wtmp,TEXT("[%lu] Хост %lu завершил соединение"),clock(), acc_sin.sin_addr.s_addr); SendMessage(hLst,LB_ADDSTRING,0,(LPARAM)wtmp); closesocket(sock); } }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case UM_SOCKET: // wParam : socket핸들 lparam : 네트워크 이벤트 { switch( WSAGETSELECTEVENT( lParam) ) { case FD_ACCEPT: { SOCKADDR_IN ClientAddr; int len = sizeof(ClientAddr); SOCKET ClientSocket = accept( (SOCKET)wParam , (SOCKADDR*)&ClientAddr, &len); // ClientSocket + hwnd + send.recv WSAAsyncSelect( ClientSocket, hwnd, UM_CLIENT , FD_WRITE|FD_READ|FD_CLOSE); } break; } } return 0; case UM_CLIENT: { SOCKET ClientSocket = (SOCKET)wParam; char buf[BUF_SIZE] = {0}; switch( WSAGETSELECTEVENT(lParam)) { case FD_READ: { recv( ClientSocket, buf, BUF_SIZE, 0); SetWindowText( hwnd, buf); } case FD_WRITE: { send( ClientSocket, buf, BUF_SIZE, 0); } break; case FD_CLOSE: break; } } return 0; case WM_LBUTTONDOWN: return 0; case WM_RBUTTONDOWN: return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc( hwnd, msg, wParam, lParam); }
int main(int argc, const char* argv[]) { HWND hWnd; MSG msg; const char* host = DEFAULT_HOST; const char* port = DEFAULT_PORT; if (argc > 2) { host = argv[1]; port = argv[2]; } hWnd = IntiInstance((HINSTANCE)GetModuleHandle(NULL)); CHECK(InitializeServer(hWnd, host, atoi(port))); while (GetMessage(&msg, NULL, 0, 0)) { if (msg.message == WM_SOCKET) { SOCKET fd = msg.wParam; int event = WSAGETSELECTEVENT(msg.lParam); int error = WSAGETSELECTERROR(msg.lParam); HandleNetEvents(hWnd, fd, event, error); } else { TranslateMessage(&msg); DispatchMessage(&msg); } } CloseServer(); return 0; }
LRESULT OnSockMsg(WPARAM wParam, LPARAM lParam) { switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT: { InsertLogMsg(_T("로그인 게이트 서버와 접속 되었습니다.")); break; } case FD_CLOSE: { break; } case FD_READ: { char szMsg[4096]; int nLen = recv((SOCKET)wParam, szMsg, sizeof(szMsg), 0); szMsg[nLen] = '\0'; InsertLogMsg(szMsg); break; } } return 0; }
short SockHandler (UINT socket, LPARAM lEvent) { switch (WSAGETSELECTEVENT (lEvent)) { case FD_READ: break; case FD_WRITE: break; case FD_OOB: break; case FD_ACCEPT: if (ssd.socket != socket) return -1; return SockAccept (); break; case FD_CONNECT: break; case FD_CLOSE: if (ssd.socket != socket) return -1; return SockClose (); break; } return 0; }
// // Handles the IDA window messages for the hidden control window. // static LRESULT CALLBACK control_window_proc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_NETEVENT: { switch (WSAGETSELECTEVENT(lp)) { case FD_ACCEPT: accept_client(); break; case FD_READ: process_client((SOCKET)wp); break; case FD_CLOSE: close_client((SOCKET)wp); break; } } break; default: return DefWindowProc(wnd, msg, wp, lp); } return 0; }
void XProc_DeleteCharacter::OnUserMessage_Socket( UINT message, WPARAM wparam, LPARAM lparam ) { if (WSAGETASYNCERROR(lparam) != 0) { g_NetworkKernel.ProcessNetworkError(); return; } switch (WSAGETSELECTEVENT(lparam)) { case FD_READ : g_NetworkKernel.ReadSocket(); break; case FD_CLOSE : //_XDWINPRINT( "SERVER MESSAGE : Socket close message" ); g_NetworkKernel.ProcessNetworkError(); g_NetworkKernel.DisconnectServer(); g_NetworkKernel.ReleaseNetwork(); ((CEmperorOfDragonsApp*)gApp)->m_proc_loginserver.m_PrevProcess_SelectCharacter = TRUE; ((CEmperorOfDragonsApp*)gApp)->m_ProcessManager.ChangeProcess( &((CEmperorOfDragonsApp*)gApp)->m_proc_loginserver ); break; } }
HRESULT CMBCBaseObj::NetCall_Write(CMBCSocket* pMBCSock, WPARAM wParam, LPARAM lParam ) { int nErr =WSAGETSELECTERROR(lParam); int nEvent = WSAGETSELECTEVENT(lParam); SOCKET socRecv = (SOCKET)wParam; //not process ASSERT(FALSE); return S_OK; }
LRESULT CMainFrame::OnCloseItem(WPARAM wParam,LPARAM lParam) { if(WSAGETSELECTEVENT(lParam) == FD_CLOSE) { DWORD pClientItem = pClientListView->CloseClient((SOCKET) wParam); } return TRUE; }
LRESULT CAsynSocket::CSocketWnd::OnWinsocketNotify(WPARAM wParam, LPARAM lParam) { if (wParam == 0 && lParam == 0) return 0; int nErrorCode = WSAGETSELECTERROR(lParam); if(m_bResolved && m_hAsyncGetHostByName == (HANDLE)wParam) //需要解析主机名 { m_hAsyncGetHostByName = NULL; m_bResolved = FALSE; m_pSocket->_OnResolve(nErrorCode); } else //已经获取到了主机名,是其他Socket消息 { if((SOCKET)wParam!=m_pSocket->m_hSocket) return 0; ////////////////////////////////////////////////////////////////// //lParam = 658833440; 在有proxy的环境容易发生此类消息进行过滤 ////////////////////////////////////////////////////////////////// UINT nEvent = WSAGETSELECTEVENT(lParam); if(nEvent==FD_CLOSE && nErrorCode==WSAECONNABORTED) return 0; switch (nEvent) { case FD_READ: //读 { DWORD nBytes; if (!m_pSocket->IOCtl(FIONREAD, &nBytes)) nErrorCode = WSAGetLastError(); if (nBytes != 0 || nErrorCode != 0) m_pSocket->_OnReceive(nErrorCode); } break; case FD_WRITE: //写 m_pSocket->_OnSend(nErrorCode); break; case FD_OOB: m_pSocket->_OnOOBData(nErrorCode); break; case FD_ACCEPT: //接收 m_pSocket->_OnAccept(nErrorCode); break; case FD_CONNECT: //连接 m_pSocket->_OnConnect(nErrorCode); break; case FD_CLOSE: //关闭 m_pSocket->_OnClose(nErrorCode); break; default: break; } } return 0; }
static LRESULT CALLBACK rb_process_events(HWND nhwnd, UINT umsg, WPARAM wparam, LPARAM lparam) { rb_fde_t *F; PF *hdl; void *data; switch (umsg) { case WM_SOCKET: { F = rb_find_fd(wparam); if(F != NULL && IsFDOpen(F)) { switch (WSAGETSELECTEVENT(lparam)) { case FD_ACCEPT: case FD_CLOSE: case FD_READ: { if((hdl = F->read_handler) != NULL) { F->read_handler = NULL; data = F->read_data; F->read_data = NULL; hdl(F, data); } break; } case FD_CONNECT: case FD_WRITE: { if((hdl = F->write_handler) != NULL) { F->write_handler = NULL; data = F->write_data; F->write_data = NULL; hdl(F, data); } } } } return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } default: return DefWindowProc(nhwnd, umsg, wparam, lparam); } return 0; }
LONG APIENTRY MyWndProc2(HWND hWnd, UINT message, UINT wParam, LONG lParam) { switch(message) { // Sockets Handling case WM_USER: DoSocketsCallback(wParam, WSAGETSELECTEVENT(lParam)); break; } return (DefWindowProc(hWnd, message, wParam, lParam)); }
void CTCPClientSocketImpl::FireEvent ( bool bIsResolveEvent, uint uiResolveId, LPARAM lType ) { // Check this is the correct thingmy #1 if ( bIsResolveEvent != m_bIsResolvingHost ) return; // Are we resolving host? If so, we got this event from WSAAsyncGetHostByName if ( m_bIsResolvingHost ) { // Check this is the correct thingmy #2 if ( uiResolveId != (uint)m_pAsyncHostResolving ) return; m_bIsResolvingHost = false; // Get error code unsigned short usError = WSAGETASYNCERROR ( lType ); // Succeeded? Continue if ( !usError ) { ConnectContinue (); } else { strcpy ( m_szLastError, "Unable to resolve" ); } return; } // Check event type switch ( WSAGETSELECTEVENT ( lType ) ) { case FD_READ: if ( m_pEventRead ) m_pEventRead ( this, m_pClass ); break; case FD_WRITE: if ( m_pEventWrite ) m_pEventWrite ( this, m_pClass ); break; case FD_CONNECT: // Client only if ( m_pEventConnect ) m_pEventConnect ( this, m_pClass ); break; case FD_CLOSE: if ( m_pEventClose ) m_pEventClose ( this, m_pClass ); break; /* case FD_ACCEPT: // Server only break; */ } }
int handleNetworkDatagramEvents(WPARAM wParam,LPARAM lParam) { switch(WSAGETSELECTEVENT(lParam)) { case FD_WRITE: javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_SENDTO_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_WRITE)\n"); #endif return 0; case FD_READ: #ifdef ENABLE_JSR_120 if (JAVACALL_OK == try_process_wma_emulator((javacall_handle)wParam)) { return 0; } #endif javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_RECVFROM_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_READ)\n"); #endif return 0; case FD_CLOSE: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_CLOSE)\n"); #endif return 0; default: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] unsolicited event %d)\n", WSAGETSELECTEVENT(lParam)); #endif break; }//end switch return 0; }
INT_PTR CALLBACK MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WSA_READ: { if (WSAGETSELECTEVENT(lParam) != FD_READ) { Admin.cSock.CloseSocket(); break; } CurrentTime = timeGetTime(); if (Admin.cSock.Receive() != 1) break; char temp[256]; int Error; int ErrorCode; while (1) { char *Msg = Admin.cSock.ReadMessage(&Error, &ErrorCode); if (Msg == NULL) break; if (Error == 1 || Error == 2) { sprintf(temp, "err wsa_read (%d),%d", Error, ErrorCode); Log(temp, "-system", 0); break; } ProcessMessage(Msg); }; } break; case WM_CLOSE: if(MessageBox(hDlg, "Você deseja fechar o aplicativo?", "Close", MB_ICONQUESTION | MB_YESNO) == IDYES) DestroyWindow(hDlg); return TRUE; case WM_DESTROY: Admin.cSock.CloseSocket(); PostQuitMessage(0); return TRUE; } return FALSE; }
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SOCKET: { // 取得有事件发生的套节字句柄 SOCKET s = wParam; // 查看是否出错 if(WSAGETSELECTERROR(lParam)) { ::closesocket(s); return 0; } // 处理发生的事件 switch(WSAGETSELECTEVENT(lParam)) { case FD_ACCEPT: // 监听中的套接字检测到有连接进入 { SOCKET client = ::accept(s, NULL, NULL); ::WSAAsyncSelect(client, hWnd, WM_SOCKET, FD_READ|FD_WRITE|FD_CLOSE); } break; case FD_WRITE: { } break; case FD_READ: { char szText[1024] = { 0 }; if(::recv(s, szText, 1024, 0) == -1) ::closesocket(s); else printf("接收数据:%s", szText); } break; case FD_CLOSE: { ::closesocket(s); } break; } } return 0; case WM_DESTROY: ::PostQuitMessage(0) ; return 0 ; } // 将我们不处理的消息交给系统做默认处理 return ::DefWindowProc(hWnd, uMsg, wParam, lParam); }
HRESULT CMBCBaseObj::NetCall_Close(CMBCSocket* pMBCSock, WPARAM wParam, LPARAM lParam ) { int nErr =WSAGETSELECTERROR(lParam); int nEvent = WSAGETSELECTEVENT(lParam); SOCKET socRecv = (SOCKET)wParam; if (socRecv == *m_pSockBase) { ChangeSelfState(MBCSTATE_NETERR); } TRACE("\n Sock Closed"); return S_OK; }
// // 함수: WndProc(HWND, UINT, WPARAM, LPARAM) // // 목적: 주 창의 메시지를 처리합니다. // // WM_COMMAND - 응용 프로그램 메뉴를 처리합니다. // WM_PAINT - 주 창을 그립니다. // WM_DESTROY - 종료 메시지를 게시하고 반환합니다. // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (message) { // 프로그램 비활성화 체크 case WM_ACTIVATEAPP : g_bActiveApp = (BOOL)wParam; break; //네트워크 메시지 case WM_NETWORK : if (WSAGETASYNCERROR(lParam)) MessageBox(g_hWnd, L"WM_NETWORK", NULL, NULL); switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT : break; case FD_CLOSE : MessageBox(g_hWnd, L"close", NULL, NULL); break; case FD_READ : ReadProc(); break; case FD_WRITE : WriteProc(); break; } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 여기에 그리기 코드를 추가합니다. EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; timeBeginPeriod(1); }
afx_msg LRESULT CServerDlg::OnSock(WPARAM wParam, LPARAM lParam) { if (WSAGETSELECTERROR(lParam)) { return 1; } switch (WSAGETSELECTEVENT(lParam)) { case FD_ACCEPT: { sockaddr_in ClientAddr; int nSize = sizeof(ClientAddr); m_ClientSock = accept(m_ListenSock, (SOCKADDR *)&ClientAddr, &nSize); WSAAsyncSelect(m_ClientSock, GetSafeHwnd(), WM_SERVER, FD_READ | FD_CLOSE); char *p = inet_ntoa(ClientAddr.sin_addr); m_StrMsg.Format("请求IP:%s:%d", p, ntohs(ClientAddr.sin_port)); char szBuf[MAXBYTE] = { 0 }; lstrcpy(szBuf, m_StrMsg.GetBuffer()); send(m_ClientSock, (const char*)&szBuf, sizeof(szBuf), 0); break; } case FD_READ: { char szBuf[MAXBYTE] = { 0 }; recv(m_ClientSock, szBuf, MAXBYTE, 0); m_StrMsg = "对方发来命令"; m_StrMsg += szBuf; break; } case FD_CLOSE: { closesocket(m_ClientSock); m_StrMsg = "对方关闭连接"; break; } } CString temp; GetDlgItemText(IDC_EDIT, temp); m_StrMsg += "\r\n----------------------\r\n"; m_StrMsg += temp; SetDlgItemText(IDC_EDIT, m_StrMsg); m_StrMsg = ""; return 0; }
BOOL CALLBACK ClientProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LPSOCKET_INFO SocketInfo; DWORD SendBytes; LPSTR psBuff; psBuff = (LPSTR)VirtualAlloc((LPVOID)NULL, (DWORD)(255), MEM_COMMIT, PAGE_READWRITE); if (WSAGETSELECTERROR(lParam)) { wsprintf(psBuff, (LPCTSTR)"Socket failed with error %d", WSAGetLastError()); AppendLog(psBuff); } else { switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT: CreateSocketInfo(wParam); break; case FD_WRITE: SocketInfo = GetSocketInfo(wParam); if (SocketInfo->DataBuff.len == 0) { SocketInfo->DataBuff.buf = SocketInfo->Buffer; SocketInfo->DataBuff.len = 0; } if (WSASend(SocketInfo->Socket, &(SocketInfo->DataBuff), 1, &SendBytes, 0, NULL, NULL) == SOCKET_ERROR) { if (WSAGetLastError() != WSAEWOULDBLOCK) { wsprintf(psBuff, (LPCTSTR)"WSASend() failed with error %d", WSAGetLastError()); AppendLog(psBuff); //FreeSocketInfo(wParam); } } else { // Update the byte count SocketInfo->BytesSEND += SendBytes; } break; case FD_CLOSE: wsprintf(psBuff, (LPCTSTR)"Closing socket %d", wParam); AppendLog(psBuff); FreeSocketInfo(wParam); break; } return FALSE; } return FALSE; }
HRESULT CMBCBaseObj::NetCall_Connect(CMBCSocket* pMBCSock, WPARAM wParam, LPARAM lParam ) { int nErr =WSAGETSELECTERROR(lParam); int nEvent = WSAGETSELECTEVENT(lParam); SOCKET socRecv = (SOCKET)wParam; //i am client ASSERT(socRecv == *pMBCSock); if (nErr ==S_OK) { //CFWriteLog("==connected, soc = %d, ip =%s", socRecv, Addr2String(pMBCSock->m_addrs.addrRemote).c_str()); ChangeSelfState(MBCSTATE_OK); } return S_OK; }
LRESULT CALLBACK SharedSocketDataReceiverWndProc(HWND wnd,UINT message,WPARAM wp,LPARAM lp) { switch (message) { case WM_SHARED_SOCKET_EVENT: { switch (WSAGETSELECTEVENT(lp)) { case FD_READ: { SOCKET data_socket=(SOCKET)wp; char type; DWORD length; PBYTE data=RecvTLVData(data_socket,&type,&length); if(data) { gSharedSocketDataReceiver(data_socket,type,length,data); }else{ //msg("Got Error on Socket\n"); } //WSAAsyncSelect: READ|CLOSE if (WSAAsyncSelect(data_socket , wnd, WM_SHARED_SOCKET_EVENT, FD_READ|FD_CLOSE ) == SOCKET_ERROR) { /* print_function("failed to async select client %d, %x data_socket=%d, message_window=%x\n", data_socket, WSAGetLastError(), data_socket, message_window); */ } } break; case FD_CLOSE: closesocket((SOCKET)wp); break; } } break; default: return DefWindowProc(wnd, message, wp, lp); } return 0; }
HRESULT CMBCHeartBeatObj::NetCall_Connect(CMBCSocket* pMBCSock, WPARAM wParam, LPARAM lParam ) { int nErr =WSAGETSELECTERROR(lParam); int nEvent = WSAGETSELECTEVENT(lParam); SOCKET socRecv = (SOCKET)wParam; //i am client ASSERT(socRecv == *pMBCSock); if (nErr ==S_OK) { m_timerLive.SetTimer(IDTIMER_LIVECHECK, INTERVAL_LIVECHECK, this, (LPARAM)this, WT_EXECUTEDEFAULT, 1000); TRACE("\n Sock Connected"); } return CMBCBaseObj::NetCall_Connect(pMBCSock, wParam, lParam); }
LRESULT BTCtcp::ProcessNotifications(HWND hWnd, LPARAM lParam) { int wsaErr = WSAGETSELECTERROR(lParam); unsigned int ui=0; TCHAR szText[MAX_LOADSTRING]; switch (WSAGETSELECTEVENT(lParam)) { case FD_ACCEPT: break; case FD_CONNECT: // connect() operation terminated if (wsaErr == ERROR_SUCCESS) { // and no error --> we are connected :) iBTCSocketStatus = 5; iBTCError = ERROR_SUCCESS; ui=IDS_SS_CONNECTED; } else { iBTCSocketStatus = 3; // "connecting..." status did not complete successfully iBTCError = wsaErr; // save error information iBTCNodeStatus=0; // no connection ui=IDS_SS_FAILED; ShowError(IDS_Err_Socket, iBTCError); } break; case FD_WRITE: bWriteReady = true; // we are notified we can send (again) WriteToSocket(); // try to send data if something is waiting in our buffer break; case FD_READ: ReadFromSocket(hWnd); // data is awaiting break; case FD_CLOSE: // connection has been closed closesocket(skBTC); // release the socket iBTCSocketStatus=1; iBTCNodeStatus=0; ui=IDS_SS_NOTHING; break; } if (ui) { // show something to user LoadString(hInst, ui, szText, MAX_LOADSTRING); SetWindowText(hStaticSocketStatus, szText); // update status window related to our TCP connection InvalidateRect(hWnd, &rcSocketStatus, true); LoadString(hInst, (iBTCSocketStatus>3) ? IDS_DISCONNECT:IDS_CONNECT, szText, MAX_LOADSTRING); SetDlgItemText(hWnd, IDC_BTNBTCCONNECT, szText); EnableWindow(GetDlgItem(hWnd, IDC_BTNSQLCONNECT), iBTCSocketStatus<2); } return 0; }
// /// DoNotification() is the SocketWindow's protected internal notification system. // TResult TSocketWindow::DoNotification(TParam1 param1, TParam2 param2) { SOCKET socket = param1; int error = (int)WSAGETSELECTERROR(param2); if (socket != SocketParent->Handle) return 0; switch (WSAGETSELECTEVENT(param2)) { case FD_READ: if (WindowNotification && (NotificationSet & NotifyRead)) { return WindowNotification->SendMessage(MsgSocketNotification, param1, param2); } SocketParent->DoReadNotification(socket, error); break; case FD_WRITE: if (WindowNotification && (NotificationSet & NotifyWrite)) { return WindowNotification->SendMessage(MsgSocketNotification, param1, param2); } SocketParent->DoWriteNotification(socket, error); break; case FD_OOB: if (WindowNotification && (NotificationSet & NotifyOOB)) { return WindowNotification->SendMessage(MsgSocketNotification, param1, param2); } SocketParent->DoOOBNotification(socket, error); break; case FD_ACCEPT: if (WindowNotification && (NotificationSet & NotifyAccept)) { return WindowNotification->SendMessage(MsgSocketNotification, param1, param2); } SocketParent->DoAcceptNotification(socket, error); break; case FD_CONNECT: if (WindowNotification && (NotificationSet & NotifyConnect)) { return WindowNotification->SendMessage(MsgSocketNotification, param1, param2); } SocketParent->DoConnectNotification(socket, error); break; case FD_CLOSE: if (WindowNotification && (NotificationSet & NotifyClose)) { return WindowNotification->SendMessage(MsgSocketNotification, param1, param2); } SocketParent->DoCloseNotification(socket, error); } return 1; }
void PASCAL CAsyncSocket::DoCallBack(WPARAM wParam, LPARAM lParam) { if (wParam == 0 && lParam == 0) return; // Has the socket be closed? CAsyncSocket* pSocket = CAsyncSocket::LookupHandle((SOCKET)wParam, TRUE); // If yes ignore message if (pSocket != NULL) return; pSocket = CAsyncSocket::LookupHandle((SOCKET)wParam, FALSE); if (pSocket == NULL) { // Must be in the middle of an Accept call pSocket = CAsyncSocket::LookupHandle(INVALID_SOCKET, FALSE); ASSERT(pSocket != NULL); pSocket->m_hSocket = (SOCKET)wParam; CAsyncSocket::DetachHandle(INVALID_SOCKET, FALSE); CAsyncSocket::AttachHandle(pSocket->m_hSocket, pSocket, FALSE); } int nErrorCode = WSAGETSELECTERROR(lParam); switch (WSAGETSELECTEVENT(lParam)) { case FD_READ: pSocket->OnReceive(nErrorCode); break; case FD_WRITE: pSocket->OnSend(nErrorCode); break; case FD_OOB: pSocket->OnOutOfBandData(nErrorCode); break; case FD_ACCEPT: pSocket->OnAccept(nErrorCode); break; case FD_CONNECT: pSocket->OnConnect(nErrorCode); break; case FD_CLOSE: pSocket->OnClose(nErrorCode); break; } }
LRESULT Client::HandleEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_SOCKET: sPlayerMain.OnSocketEvent(wParam, WSAGETSELECTERROR(lParam), WSAGETSELECTEVENT(lParam)); return 0; case WM_CREATE: LoadContent(); return 0; case WM_KEYDOWN: KeyDown(wParam); return 0; case WM_PAINT: Draw(hwnd); return 0; case WM_LBUTTONDBLCLK: MouseLDButtonDown(lParam); return 0; case WM_MBUTTONDOWN: MouseMButtonDown(lParam); return 0; case WM_LBUTTONDOWN: MouseLButtonDown(lParam); return 0; case WM_RBUTTONDOWN: MouseRButtonDown(lParam); return 0; case WM_MOUSEMOVE: MouseMove(lParam); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); }
//============================================================================= int XSocket::iOnSocketEvent(WPARAM wParam, LPARAM lParam) { int WSAEvent; PutLogList("iOnSocketEvent"); if (m_cType != XSOCK_NORMALSOCK) return XSOCKEVENT_SOCKETMISMATCH; if (m_cType == NULL) return XSOCKEVENT_NOTINITIALIZED; if ((SOCKET)wParam != m_Sock) return XSOCKEVENT_SOCKETMISMATCH; WSAEvent = WSAGETSELECTEVENT(lParam); switch (WSAEvent) { case FD_CONNECT: if (WSAGETSELECTERROR(lParam) != 0) { if (bConnect(m_pAddr, m_iPortNum, m_uiMsg) == FALSE) return XSOCKEVENT_SOCKETERROR; return XSOCKEVENT_RETRYINGCONNECTION; } else { m_bIsAvailable = TRUE; return XSOCKEVENT_CONNECTIONESTABLISH; } break; case FD_READ: if (WSAGETSELECTERROR(lParam) != 0) { m_WSAErr = WSAGETSELECTERROR(lParam); return XSOCKEVENT_SOCKETERROR; } else return _iOnRead(); break; case FD_WRITE: return _iSendUnsentData(); break; case FD_CLOSE: m_cType = XSOCK_SHUTDOWNEDSOCK; return XSOCKEVENT_SOCKETCLOSED; break; } return XSOCKEVENT_UNKNOWN; }
void CListener::ProcessSocketMsg(WPARAM wParam, LPARAM lParam) { if (WSAGETSELECTERROR(lParam)) { // Display the error and close the socket CloseConnection(wParam); return; } switch(WSAGETSELECTEVENT(lParam)) { case FD_ACCEPT: { SOCKADDR_IN ClientAddr = {0}; int iLen = sizeof(ClientAddr); accept(wParam, (LPSOCKADDR)&ClientAddr, &iLen); break; } case FD_READ: { // Receive data from the socket in // wParam ProcessRead(wParam); break; } case FD_WRITE: { // The socket in wParam is ready // for sending data break; } case FD_CLOSE: { // The connection is now closed CloseConnection(wParam); break; } } }