int Client(int argc, char** argv) { long type = CLIENT_TO_SERVER; char request[BUFF]; Mesg snd; if(OpenQueue() < 0){ return 1; } done = 1; if(CreateReadThread() < 0) return -1; while (running) { if(done) { rc = ReadArguments(request, argc, argv); if(rc < 0) { return 0; } else if(rc == 1) { continue; } done = 0; strncpy(snd.mesg_data, request, BUFF); snd.mesg_type = type; if(SendMessage(msgQueue, &snd) < 0) { return -1; } } } return 0; }
bool TSocketConnection::Iteration() { auto& Socket = *mSocket; try { Socket.CreateTcp(true); if ( !Socket.IsConnected() ) { mConnectionRef = Socket.Connect( mServerAddress ); // if blocking and returns invalid, then the socket has probably error'd if ( !mConnectionRef.IsValid() ) { throw Soy::AssertException("Connecton failed"); } FlushRequestQueue(); if ( !mReadThread ) { mReadThread = CreateReadThread( mSocket, mConnectionRef ); } } } catch ( std::exception& e ) { Shutdown(); std::stringstream Error; Error << "Failed to create & connect TCP socket: " << e.what(); auto ErrorStr = Error.str(); mOnError.OnTriggered( ErrorStr ); return true; } // only wake up when something happens now SetWakeMode( SoyWorkerWaitMode::Wake ); return true; }