bool DummyClientSession::ConnectRequest() { if (mConnected) { /// 이미 접속 된 상태인데 이쪽으로 들어오면 잘못된 것 CRASH_ASSERT(false); return false; } // Set up our socket address structure ZeroMemory(&mConnectAddr, sizeof(mConnectAddr)); mConnectAddr.sin_port = htons(CONNECT_PORT); mConnectAddr.sin_family = AF_INET; mConnectAddr.sin_addr.s_addr = inet_addr(CONNECT_ADDR); OverlappedConnectContext* context = new OverlappedConnectContext(this); if (FALSE == ConnectEx(mSocket, (sockaddr*)&mConnectAddr, sizeof(SOCKADDR_IN), NULL, 0, NULL, (LPWSAOVERLAPPED)context)) { if (WSAGetLastError() != WSA_IO_PENDING) { DeleteIoContext(context); printf_s("DummyClientSession::ConnectRequest Error : %d\n", GetLastError()); } } return true; }
bool ClientSession::PostConnect() { CRASH_ASSERT(LThreadType == THREAD_MAIN); // 바인드 한번만 하게 처리해야함 { struct sockaddr_in addr; ZeroMemory( &addr, sizeof( addr ) ); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = 0; int rc = bind( mSocket, (SOCKADDR*)&addr, sizeof( addr ) ); if ( rc != 0 ) { printf( "bind failed: %d\n", WSAGetLastError() ); return 1; } } HANDLE handle = CreateIoCompletionPort( (HANDLE)mSocket, GIocpManager->GetComletionPort(), ( ULONG_PTR )this, 0 ); if ( handle != GIocpManager->GetComletionPort() ) { printf_s( "[DEBUG] CreateIoCompletionPort error: %d\n", GetLastError() ); return false; } OverlappedConnectContext* connectContext = new OverlappedConnectContext( this ); DWORD bytes = 0; DWORD flags = 0; connectContext->mWsaBuf.len = 0; connectContext->mWsaBuf.buf = nullptr; sockaddr_in addr; ZeroMemory( &addr, sizeof( addr ) ); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr( "127.0.0.1" ); addr.sin_port = htons( CONNECT_PORT ); if ( FALSE == ConnectEx( mSocket, (SOCKADDR*)&addr, sizeof( addr ), NULL, 0, NULL, ( LPOVERLAPPED )connectContext ) ) { if (WSAGetLastError() != WSA_IO_PENDING) { DeleteIoContext( connectContext ); printf_s("AcceptEx Error : %d\n", GetLastError()); return false; } } return true; }
bool ServerSession::ConnectRequest() { if (mConnected) { /// 이미 접속 된 상태인데 이쪽으로 들어오면 잘못된 것 CRASH_ASSERT(false); return false; } // Set up our socket address structure SOCKADDR_IN serverSockAddr; ZeroMemory(&serverSockAddr, sizeof(serverSockAddr)); serverSockAddr.sin_port = htons(mPort); serverSockAddr.sin_family = AF_INET; serverSockAddr.sin_addr.s_addr = inet_addr(mServerAddr); if (SOCKET_ERROR == bind(mSocket, (SOCKADDR*)&serverSockAddr, sizeof(serverSockAddr))) { printf_s("ServerSession::ConnectRequest() bind error: %d\n", GetLastError()); return false; } HANDLE handle = CreateIoCompletionPort((HANDLE)mSocket, GIocpManager->GetComletionPort(), (ULONG_PTR)this, 0); if (handle != GIocpManager->GetComletionPort()) { printf_s("ServerSession::ConnectRequest() CreateIoCompletionPort error: %d\n", GetLastError()); return false; } OverlappedConnectContext* context = new OverlappedConnectContext(this); if (FALSE == ConnectEx(mSocket, (sockaddr*)&serverSockAddr, sizeof(SOCKADDR_IN), NULL, 0, NULL, (LPWSAOVERLAPPED)context)) { if (WSAGetLastError() != WSA_IO_PENDING) { DeleteIoContext(context); printf_s("ServerSession::ConnectRequest Error : %d\n", GetLastError()); } } return true; }
void dbFTPConnect ( char* szString, char* szString2, char* szString3, int iUseWindow ) { ConnectEx ( ( DWORD ) szString, ( DWORD ) szString2, ( DWORD ) szString3, iUseWindow ); }