virtual int updateLogLevel( const char* logLevel) { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_UPDATE_LOG_LEVEL_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body: ExecutorUpdateLogLevelRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.logLevel, logLevel, EXECUTOR_BUFFER_SIZE); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorUpdateLogLevelResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; return response.status; }
virtual int authenticatePassword( const char* username, const char* password) { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_AUTHENTICATE_PASSWORD_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body. ExecutorAuthenticatePasswordRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE); Strlcpy(request.password, password, EXECUTOR_BUFFER_SIZE); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorAuthenticatePasswordResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; return response.status; }
virtual int validateUser( const char* username) { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_VALIDATE_USER_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body. ExecutorValidateUserRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorValidateUserResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; return response.status; }
void Video(void) { uchar CurRow,CurCol; // if (CheckKeyboardXMEGA()) return; if (GrafView) { GrafView--; if (!GrafView) ClearGraf(); else return; } IniLCDMem(); TimeToBuf(); //---- output CharSet ---------------- SendBlock(&buf[0],TxtHomeAddr,DisplCols); SendBlock(&buf[Str2],TxtHomeAddr+DisplCols*2,DisplCols*(SUM_LINE_DISP-4)); if(Menu) SendCmd(cmd8LineCurs); else SendCmd(cmd3LineCurs); //-- установить курсор -- CurCol=(AdinB+Mark) % DisplCols; CurRow=(AdinB+Mark) / DisplCols;// + 2; Send2(cmdPozCurs,((int)CurRow * 256)+ CurCol); //0x0101); VideoSost(); }
virtual int challengeLocal( const char* username, char challengeFilePath[EXECUTOR_BUFFER_SIZE]) { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_CHALLENGE_LOCAL_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body. ExecutorChallengeLocalRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.user, username, EXECUTOR_BUFFER_SIZE); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorChallengeLocalResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; Strlcpy(challengeFilePath, response.challenge, EXECUTOR_BUFFER_SIZE); return response.status; }
virtual int removeFile( const char* path) { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_REMOVE_FILE_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body. ExecutorRemoveFileRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorRemoveFileResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; return response.status; }
virtual FILE* openFile( const char* path, int mode) { AutoMutex autoMutex(_mutex); if (mode != 'r' && mode != 'w' && mode != 'a') return NULL; // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_OPEN_FILE_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return NULL; // Send request body. ExecutorOpenFileRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE); request.mode = mode; if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return NULL; // Receive the response ExecutorOpenFileResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return NULL; // Receive descriptor (if response successful). if (response.status == 0) { int fds[1]; if (RecvDescriptorArray(_sock, fds, 1) != 0) return NULL; if (fds[0] == -1) return NULL; else { if (mode == 'r') return fdopen(fds[0], "rb"); else return fdopen(fds[0], "wb"); } } return NULL; }
/***************************************************************************** * RetxHandle: handle a retx query *****************************************************************************/ static void RetxHandle(void) { ssize_t i_size = RETX_HEADER_SIZE - p_retx_block->i_size; uint8_t *p_buffer = p_retx_block->p_data + p_retx_block->i_size; sockaddr_t sout; socklen_t i_len = sizeof(sout); i_size = recvfrom( i_retx_fd, p_buffer, i_size, 0, &sout.so, &i_len ); if ( i_size < 0 && errno != EAGAIN && errno != EINTR ) { msg_Err( NULL, "unrecoverable read error, dying (%s)", strerror(errno) ); exit(EXIT_FAILURE); } if ( i_size <= 0 ) return; p_retx_block->i_size += i_size; if ( p_retx_block->i_size != RETX_HEADER_SIZE ) { if ( b_retx_tcp ) return; msg_Err( NULL, "invalid retx packet received, dying" ); exit(EXIT_FAILURE); } if ( !retx_check(p_retx_block->p_data) ) { msg_Err( NULL, "invalid retx packet, dying" ); exit(EXIT_FAILURE); } uint16_t i_seqnum = retx_get_seqnum(p_retx_block->p_data); uint16_t i_num = retx_get_num(p_retx_block->p_data); block_t *p_block = p_retx_first; p_retx_block->i_size = 0; while ( p_block != NULL ) { if ( rtp_get_seqnum(p_block->p_data) == i_seqnum ) break; p_block = p_block->p_next; } if ( p_block == NULL ) { msg_Warn( NULL, "unable to find packet %hu for retx", i_seqnum ); return; } while ( i_num && p_block != NULL ) { SendBlock( i_retx_fd, i_len ? &sout.so : NULL, i_len, p_block ); p_block = p_block->p_next; i_num--; } if ( i_num ) msg_Warn( NULL, "unable to find %hu packets after %hu", i_num, i_seqnum ); }
void InitLCD(void) { LCD_STARTUP; LCD_CTRL_DIR_OUT(); SetWR; SetRD; SetCE; IniLCDMem(); SendBlock(&(ExtCG[0]),CGHomeAddr,SumExtCG*8); SendSim(Tire,1); //- SendSim(0x00,7); //Пробел }
int QymodemTx::SendY(const char* fileName, size_t size, InStream& in, unsigned timeout) { Use1KBlocks = true; quint8 buffer[128]; int result = MakeBlock0(buffer,fileName,size); if(result<0) return result; result = SendInitialise(timeout); if(result<0 && result!=ErrorBlockRetriesExceded) return result; emit Information("Sending "+QString(fileName),QymodemTx::InfoSending); BlockNumber = 0; result = SendBlock(buffer,sizeof(buffer)); if(result<0) return result; result = InChar(SendTimeout); if(result<0) return result; if(result!=ModeChar) return ErrorReceiverNotBehaving; result = SendAll(in); if(result<0) return result; result = InChar(SendTimeout); if(result<0) return result; if(result!=ModeChar) return ErrorReceiverNotBehaving; memset(buffer,0,sizeof(buffer)); BlockNumber = 0; result = SendBlock(buffer,sizeof(buffer)); if(result<0) return result; emit Percent(100); return 0; }
/***************************************************************************** * Demux: read packet and send them to decoders ***************************************************************************** * Returns -1 in case of error, 0 in case of EOF, 1 otherwise *****************************************************************************/ static int MjpgDemux( demux_t *p_demux ) { demux_sys_t *p_sys = p_demux->p_sys; int i; if( p_sys->b_still && p_sys->i_still_end ) { /* Still frame, wait until the pause delay is gone */ mwait( p_sys->i_still_end ); p_sys->i_still_end = 0; return 1; } if( !Peek( p_demux, true ) ) { msg_Warn( p_demux, "cannot peek data" ); return 0; } if( p_sys->i_data_peeked < 4 ) { msg_Warn( p_demux, "data shortage" ); return 0; } i = 3; FIND_NEXT_EOI: while( !( 0xFF == p_sys->p_peek[i-1] && 0xD9 == p_sys->p_peek[i] ) ) { if( 0xFF == p_sys->p_peek[i-1] && 0xD8 == p_sys->p_peek[i] ) { p_sys->i_level++; msg_Dbg( p_demux, "we found another JPEG SOI at %d", i ); } i++; if( i >= p_sys->i_data_peeked ) { msg_Dbg( p_demux, "did not find JPEG EOI in %d bytes", p_sys->i_data_peeked ); if( !Peek( p_demux, false ) ) { msg_Warn( p_demux, "no more data is available at the moment" ); return 0; } } } i++; msg_Dbg( p_demux, "JPEG EOI detected at %d", i ); p_sys->i_level--; if( p_sys->i_level > 0 ) goto FIND_NEXT_EOI; return SendBlock( p_demux, i ); }
/** Send data. A zero sized block terminates the transfer. @param data The data to transfer. @param size Size of data. @return Zero if successful, or a negative error value if failed. @pre SendInitialise() must have been successful. */ int QymodemTx::SendData(const quint8* data, size_t size) { do { int result = SendBlock(data, size); if(result<0) return result; data += result; size -= result; } while(size); return 0; }
void OnConnect() { gettime(&m_connect, NULL); m_b_active = true; { double tconnect = Diff(m_create, m_connect); // g_min_time = tconnect < g_min_time ? tconnect : g_min_time; g_max_time = tconnect > g_max_time ? tconnect : g_max_time; g_tot_time += tconnect; g_ant += 1; } SendBlock(); m_b_client = true; }
virtual int authenticateLocal( const char* challengeFilePath, const char* response) { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_AUTHENTICATE_LOCAL_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body. ExecutorAuthenticateLocalRequest request; memset(&request, 0, sizeof(request)); Strlcpy(request.challenge, challengeFilePath, EXECUTOR_BUFFER_SIZE); Strlcpy(request.response, response, EXECUTOR_BUFFER_SIZE); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorAuthenticateLocalResponse response_; if (RecvBlock(_sock, &response_, sizeof(response_)) != sizeof(response_)) { return -1; } return response_.status; }
void process_input(char *recvbuf, int recv_buf_cnt, int* csock) { char replybuf[1024]={'\0'}; char buffer[1024]; memset(&buffer, 0, 1024); int k=ProcessInputBuffer(recvbuf); if (k == 0) { WriteToTheFile(recvbuf); } else if (k == 1) { printf("Client Opened"); memset(recvbuf, '\0', sizeof(recvbuf)); char sendbuffer[256] = "@1\n\n\t1.Blob Store\n\n$1$1$#"; strcpy(recvbuf, sendbuffer); } else if (k == 3) { ManageUsersData(recvbuf); } else if (k == 4) { ProcessMainFunction(recvbuf); } else if (k == 5) { ProcessFileNameInformation(recvbuf); } else if (k == 6) { printf("end block is called"); strcpy(recvbuf, "$File Read Successfully#"); } else if (k == 7) { DoFileProcessingInDatabase(recvbuf); } else if (k == 8) { SendBlock(recvbuf); } replyto_client(recvbuf, csock); replybuf[0] = '\0'; }
void Server::SendFilePartsTCP(fd_set& clients) { for (auto client = this->tcpClients.begin(); client != this->tcpClients.end(); ++client) { if (FD_ISSET((*client)->first, &clients) > 0) { try { SendBlock(*client); } catch (std::runtime_error e) { std::cout << e.what() << std::endl; RemoveTCPClient(client); std::cout << CLIENTS_ONLINE; if (client == this->tcpClients.end()) break; } } } }
virtual int daemonizeExecutor() { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_DAEMONIZE_EXECUTOR_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Receive the response ExecutorDaemonizeExecutorResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; return response.status; }
void OnLine(const std::string& line) { gettime(&m_reply, NULL); m_b_active = true; { double treply = Diff(m_send, m_reply); // g_min_time2 = treply < g_min_time2 ? treply : g_min_time2; g_max_time2 = treply > g_max_time2 ? treply : g_max_time2; g_tot_time2 += treply; g_ant2 += 1; } // if (line != g_data) { fprintf(stderr, "\n%s\n%s\n", line.c_str(), g_data.c_str()); fprintf(stderr, "(reply did not match data - exiting)\n"); exit(-1); } // gBytesIn += GetBytesReceived(true); gBytesOut += GetBytesSent(true); if (m_b_one) { SetCloseAndDelete(); } else if (g_b_repeat && g_b_limit) { SendBlock(); } // add another if (!m_b_created && (!g_b_limit || !g_b_off) && !g_b_instant) { MySocket *p = new MySocket(Handler(), m_b_one); p -> SetDeleteByHandler(); p -> Open(gHost, gPort); Handler().Add(p); m_b_created = true; } }
virtual int ping() { AutoMutex autoMutex(_mutex); // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_PING_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; ExecutorPingResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; if (response.magic == EXECUTOR_PING_MAGIC) return 0; return -1; }
void VideoSost(void) { int ic; BlkW=1; Ad_Buf=Str2d; for (ic=Str2d; ic < Str2; ic++) buf[ic]=' '; // Ad_Buf=Str4; /* if (ds18b20_ReadROM()) Ad_Buf+=2; w_int(&Buf1W[0],StStStS); buf[Ad_Buf++]='-'; w_int(&Buf1W[4],StStStS); w_int(&SumAnswers,SSSS);*/ pmInfoProg405(); SendBlock(&buf[Str2d],TxtHomeAddr+DisplCols*(SUM_LINE_DISP-1),DisplCols); // pmInfoProg405(); // w_txt(I2C1_Buffer_Tx); // w_txt(I2C1_Buffer_Rx); // w_int(&GlobData,SSSS); //w_txt() //SendBlock(&buf[Str2d],TxtHomeAddr+DisplCols*(SUM_LINE_DISP-1),DisplCols); }
/***************************************************************************** * Entry point *****************************************************************************/ int main( int i_argc, char **pp_argv ) { int c; int i_priority = -1; int i_ttl = 0; bool b_udp = false; struct pollfd pfd[2]; while ( (c = getopt( i_argc, pp_argv, "i:t:wo:x:X:Um:R:h" )) != -1 ) { switch ( c ) { case 'i': i_priority = strtol( optarg, NULL, 0 ); break; case 't': i_ttl = strtol( optarg, NULL, 0 ); break; case 'w': b_overwrite_timestamps = true; break; case 'o': { struct in_addr maddr; if ( !inet_aton( optarg, &maddr ) ) usage(); i_ssrc = maddr.s_addr; b_overwrite_ssrc = true; break; } case 'x': i_retx_buffer = strtoll( optarg, NULL, 0 ) * 27000; break; case 'X': i_retx_fd = OpenSocket( optarg, 0, 0, 0, NULL, &b_retx_tcp, NULL ); if ( i_retx_fd == -1 ) { msg_Err( NULL, "unable to set up retx with %s\n", optarg ); exit(EXIT_FAILURE); } pfd[1].fd = i_retx_fd; pfd[1].events = POLLIN | POLLERR | POLLRDHUP | POLLHUP; p_retx_block = malloc( sizeof(block_t) + RETX_HEADER_SIZE ); p_retx_block->p_data = (uint8_t *)p_retx_block + sizeof(block_t); p_retx_block->i_size = 0; break; case 'U': b_udp = true; break; case 'm': i_asked_payload_size = strtol( optarg, NULL, 0 ); break; case 'R': i_rtp_header_size = strtol( optarg, NULL, 0 ); break; case 'h': default: usage(); break; } } if ( optind >= i_argc - 1 ) usage(); i_input_fd = OpenSocket( pp_argv[optind], 0, DEFAULT_PORT, 0, NULL, &b_input_tcp, NULL ); if ( i_input_fd == -1 ) { msg_Err( NULL, "unable to open input socket" ); exit(EXIT_FAILURE); } optind++; pfd[0].fd = i_input_fd; pfd[0].events = POLLIN | POLLERR | POLLRDHUP | POLLHUP; while ( optind < i_argc ) { p_outputs = realloc( p_outputs, ++i_nb_outputs * sizeof(output_t) ); p_outputs[i_nb_outputs - 1].i_fd = OpenSocket( pp_argv[optind++], i_ttl, 0, DEFAULT_PORT, &p_outputs[i_nb_outputs - 1].i_weight, NULL, NULL ); if ( p_outputs[i_nb_outputs - 1].i_fd == -1 ) { msg_Err( NULL, "unable to open output socket" ); exit(EXIT_FAILURE); } p_outputs[i_nb_outputs - 1].i_weighted_size = p_outputs[i_nb_outputs - 1].i_remainder = 0; i_max_weight += p_outputs[i_nb_outputs - 1].i_weight; } msg_Dbg( NULL, "%d outputs weight %u%s", i_nb_outputs, i_max_weight, i_retx_fd != -1 ? ", with retx" : "" ); if ( i_priority > 0 ) { struct sched_param param; int i_error; memset( ¶m, 0, sizeof(struct sched_param) ); param.sched_priority = i_priority; if ( (i_error = pthread_setschedparam( pthread_self(), SCHED_RR, ¶m )) ) { msg_Warn( NULL, "couldn't set thread priority: %s", strerror(i_error) ); } } for ( ; ; ) { uint64_t i_current_date; if ( poll( pfd, i_retx_fd == -1 ? 1 : 2, -1 ) < 0 ) { int saved_errno = errno; msg_Warn( NULL, "couldn't poll(): %s", strerror(errno) ); if ( saved_errno == EINTR ) continue; exit(EXIT_FAILURE); } i_current_date = wall_Date(); if ( (pfd[0].revents & (POLLERR | POLLRDHUP | POLLHUP)) || (i_retx_fd != -1 && (pfd[1].revents & (POLLERR | POLLRDHUP | POLLHUP)))) { msg_Err( NULL, "poll error\n" ); exit(EXIT_FAILURE); } if ( pfd[0].revents & POLLIN ) { /* Read input block */ ssize_t i_size, i_wanted_size; uint8_t *p_read_buffer; if ( b_udp ) i_wanted_size = i_asked_payload_size + RTP_HEADER_SIZE; else i_wanted_size = i_asked_payload_size + i_rtp_header_size; if ( p_input_block == NULL ) { if ( b_udp ) { p_input_block = malloc( sizeof(block_t) + i_asked_payload_size + RTP_HEADER_SIZE ); p_input_block->i_size = RTP_HEADER_SIZE; } else { p_input_block = malloc( sizeof(block_t) + i_asked_payload_size + i_rtp_header_size ); p_input_block->p_data = (uint8_t *)p_input_block + sizeof(block_t); p_input_block->i_size = 0; } p_input_block->p_data = (uint8_t *)p_input_block + sizeof(block_t); } p_read_buffer = p_input_block->p_data + p_input_block->i_size; i_wanted_size -= p_input_block->i_size; i_size = read( i_input_fd, p_read_buffer, i_wanted_size ); if ( i_size < 0 && errno != EAGAIN && errno != EINTR ) { msg_Err( NULL, "unrecoverable read error, dying (%s)", strerror(errno) ); exit(EXIT_FAILURE); } if ( i_size <= 0 ) continue; p_input_block->i_size += i_size; if ( b_input_tcp && i_size != i_wanted_size ) continue; if ( b_udp ) { rtp_set_hdr( p_input_block->p_data ); rtp_set_type( p_input_block->p_data, RTP_TYPE_TS ); rtp_set_seqnum( p_input_block->p_data, i_rtp_seqnum ); i_rtp_seqnum++; rtp_set_ssrc( p_input_block->p_data, (uint8_t *)&i_ssrc ); /* this isn't RFC-compliant, but we assume that at the other * end, the RTP header will be stripped */ rtp_set_timestamp( p_input_block->p_data, i_current_date / 300 ); } else { if ( b_overwrite_ssrc ) rtp_set_ssrc( p_input_block->p_data, (uint8_t *)&i_ssrc ); if ( b_overwrite_timestamps ) rtp_set_timestamp( p_input_block->p_data, i_current_date / 300 ); } /* Output block */ output_t *p_output = NextOutput(); SendBlock( p_output->i_fd, NULL, 0, p_input_block ); p_output->i_weighted_size += (i_size + p_output->i_remainder) / p_output->i_weight; p_output->i_remainder = (i_size + p_output->i_remainder) % p_output->i_weight; if ( i_retx_fd != -1 ) RetxQueue( p_input_block, i_current_date ); else free( p_input_block ); p_input_block = NULL; } if ( i_retx_fd != -1 && (pfd[1].revents & POLLIN) ) RetxHandle(); } return EXIT_SUCCESS; }
/*! * @return A block of data with a file descriptor to transmit it out */ SendBlock requestRead() { return SendBlock(pRead, frames.empty()?0:frames.front().size, frames.empty()?-1:frames.front().id.fd); }
int SendControlByte(int cb) { return SendBlock(I2C_CONTROLSWITCH_ID,&cb,1); }
static int MimeDemux( demux_t *p_demux ) { demux_sys_t *p_sys = p_demux->p_sys; int i_size, i; bool b_match = CheckMimeHeader( p_demux, &i_size ); if( i_size > 0 ) { stream_Read( p_demux->s, NULL, i_size ); } else if( i_size < 0 ) { return 0; } else { // No MIME header, assume OK b_match = true; } if( !Peek( p_demux, true ) ) { msg_Warn( p_demux, "cannot peek data" ); return 0; } i = 0; i_size = strlen( p_sys->psz_separator ) + 2; if( p_sys->i_data_peeked < i_size ) { msg_Warn( p_demux, "data shortage" ); return 0; } for( ;; ) { while( !( p_sys->p_peek[i] == '-' && p_sys->p_peek[i+1] == '-' ) ) { i++; i_size++; if( i_size >= p_sys->i_data_peeked ) { msg_Dbg( p_demux, "MIME boundary not found in %d bytes of " "data", p_sys->i_data_peeked ); if( !Peek( p_demux, false ) ) { msg_Warn( p_demux, "no more data is available at the " "moment" ); return 0; } } } if( !strncmp( p_sys->psz_separator, (char *)(p_sys->p_peek + i + 2), strlen( p_sys->psz_separator ) ) ) { break; } i++; i_size++; } if( !b_match ) { msg_Err( p_demux, "discard non-JPEG part" ); stream_Read( p_demux->s, NULL, i ); return 0; } return SendBlock( p_demux, i ); }
virtual int startProviderAgent( const char* module, const String& pegasusHome, const String& userName, int& pid, AnonymousPipe*& readPipe, AnonymousPipe*& writePipe) { AutoMutex autoMutex(_mutex); readPipe = 0; writePipe = 0; // Reject strings longer than EXECUTOR_BUFFER_SIZE. size_t moduleNameLength = strlen(module); if (moduleNameLength >= EXECUTOR_BUFFER_SIZE) return -1; CString userNameCString = userName.getCString(); size_t userNameLength = strlen(userNameCString); if (userNameLength >= EXECUTOR_BUFFER_SIZE) return -1; // Send request header: ExecutorRequestHeader header; header.code = EXECUTOR_START_PROVIDER_AGENT_MESSAGE; if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header)) return -1; // Send request body. ExecutorStartProviderAgentRequest request; memset(&request, 0, sizeof(request)); memcpy(request.module, module, moduleNameLength); memcpy(request.userName, userNameCString, userNameLength); if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request)) return -1; // Receive the response ExecutorStartProviderAgentResponse response; if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response)) return -1; // Check response status and pid. if (response.status != 0) return -1; // Get pid: pid = response.pid; // Receive descriptors. int descriptors[2]; int result = RecvDescriptorArray(_sock, descriptors, 2); if (result == 0) { int readFd = descriptors[0]; int writeFd = descriptors[1]; // Create to and from AnonymousPipe instances to correspond to // the pipe descriptors created above. char readFdStr[32]; char writeFdStr[32]; sprintf(readFdStr, "%d", readFd); sprintf(writeFdStr, "%d", writeFd); readPipe = new AnonymousPipe(readFdStr, 0); writePipe = new AnonymousPipe(0, writeFdStr); } return result; }
bool CComPort::SendASCII(const char* str) { if (!str) return false; return SendBlock((BYTE*)str,strlen(str)); }