void RTMFPServer::receive(RTMFPReceiving * rtmfpReceiving) { // Process packet if (!rtmfpReceiving) return; if (rtmfpReceiving->socket == _shellSocket) { return handleShellCommand(rtmfpReceiving); } Session* pSession = NULL; if(rtmfpReceiving->id==0) { DEBUG("Handshaking"); pSession = &_handshake; } else pSession = _sessions.find(rtmfpReceiving->id); if(!pSession) return; // No warn because can have been deleted during decoding threading process if(!pSession->checked) { (bool&)pSession->checked = true; CookieComputing* pCookieComputing = pSession->peer.object<CookieComputing>(); _handshake.commitCookie(pCookieComputing->value); pCookieComputing->release(); } SocketAddress oldAddress = pSession->peer.address; if(pSession->setEndPoint(rtmfpReceiving->socket,rtmfpReceiving->address) && rtmfpReceiving->id != 0) _sessions.changeAddress(oldAddress,*pSession); pSession->receive(*rtmfpReceiving->pPacket); }
int main() { //Set up to ignore SIGINT and SIGQUIT struct sigaction newact, oldact; newact.sa_handler = SIG_IGN; sigaction(SIGINT, &newact, &oldact); sigaction(SIGQUIT, &newact, &oldact); while(1) { char* prompt = setPromptString(); printf("%s", prompt); char* input_string = getInputString(); //Initialize array to hold commands size_t commands_alloc_size = COMMANDS_INITIAL_SIZE; int num_commands = 0; command* commands = malloc(sizeof(command) * commands_alloc_size); fillCommandArray(input_string, &commands, &num_commands, &commands_alloc_size); bool wasShellCommand = handleShellCommand(commands[0]); if (wasShellCommand == false) { int** fds = createPipes(num_commands); for (int i = 0; i < num_commands; ++i) { pid_t fork_pid = fork(); if (fork_pid == -1) { perror("Fork failed"); exit(1); } //Child process else if (fork_pid == 0) { sigaction(SIGINT, &oldact, NULL); sigaction(SIGQUIT, &oldact, NULL); executeCommand(fds, num_commands, commands[i], i); } } //Clean up the shell process closeAllPipes(fds, num_commands); waitForAllChildProcesses(num_commands); freeCommandArray(commands, num_commands); } } return 0; }