void* affichage (void *arg) { char my_message[60]; #ifdef DEBUG printf("affichage va s'abonner\n "); #endif if (aboMsg(666) != 0){ printf("Erreur lors de l'abonnement du thread affichage\n"); pthread_exit(NULL); } while(1){ while (_flagsusp == 1){ sleep(2); } if (_flagstop && recvMsg(1, 666, NULL) <= 0){ desaboMsg(666); printf("Arrêt de la tâche de lecture\n"); pthread_exit(NULL); } if (recvMsg(1, 666, NULL) != 0){ /*On est obligé de vérifier s'il y a des messages car on ne veut pas le caractère bloquant ici (en cas de _flagstop levé)*/ recvMsg(0, 666, my_message); printf("%s\n",my_message); } sleep(1); /*On attend un peu*/ } pthread_exit(NULL); }
// receive a message and place it in msg (which is a buffer of size length). // Return the number of read bytes. // blocking size_t IPC_receive(void *msg, size_t length) { size_t header_size, s, left, msg_len; int fd; s = 0; fd = get_fd_for_receive(); if (fd < 0) { printf("Node %i has fd=%i in recv\n", node_id, fd); return 0; } #ifdef DEBUG printf("Node %i is receiving a message with fd=%i\n", node_id, fd); #endif // receive the message_header header_size = recvMsg(fd, (void*) msg, sizeof(struct message_header)); // receive the message content msg_len = ((struct message_header*) msg)->len; left = msg_len - header_size; if (left > 0) { s = recvMsg(fd, (void*) ((char*) msg + header_size), left); } return header_size + s; }
void main() { int i,RcvId; void *msg; int screen; chan = makeChan(); screen = open("/dev/screen",O_PROC, chan); if (screen == -1) { perror("Shit!"); exit(1); } retexit(1); scrSwitch(screen, SCRO_This); while(1) { RcvId = recvMsg(chan, &msg); switch (* (int *)msg) { case PMSG_GetScr: VideoMode(); InitializeStars(); EditPalette(); getRaster(); check=1; initKey(); setRaster(VBIRute,250); break; case PMSG_LoseScr: freeRaster(); scrSwitch(screen, SCRO_Next); break; } replyMsg(RcvId,0); } }
void host::run() { printf("From %s: host::run called.\n",_name); bool bRun = true; size_t sz; while (bRun) { if ((sz = _pcomm->readMsg(_inbuf, BUFF_SIZE)) > 0) { switch (_inbuf[0]) { case MSGTYPE_CMSG: sendMsg(&_inbuf[1], (sz-1)); break; case MSGTYPE_HMSG: recvMsg(&_inbuf[1], (sz-1)); break; case MSGTYPE_CQUIT: bRun = false; break; default: printf("From %s: unknown message type %d. The message is dropped.\n",_name,_inbuf[0]); } } } }
void Mana::newConnect() { m_tcpSocket = this->m_server->nextPendingConnection(); connect(this->m_tcpSocket,SIGNAL(readyRead()),this,SLOT(recvMsg())); m_canSendMsg = true; qDebug() << m_tcpSocket->peerAddress().toString(); }
int main(int argc, char** argv) { pthread_t recvpid; pthread_t sendpid; MSG_S rcvmsg; int rcvData; MSGQUEUEHANDLE pCxt = createMsgQueue(SIZE); if (NULL == pCxt) { LOGE(TAG, "createMsgQueue failed!\n"); return -1; } pthread_create(&sendpid, NULL, sendThread, pCxt); rcvmsg.m_pMsgData = &rcvData; while(1) { //sleep(1); recvMsg(pCxt, &rcvmsg); printMsg(&rcvmsg); } return 0; }
bool Connection::receiveArgs() { // Get argc recvMsg(&m_argc); const uint32_t ARG_MAX = 1024; if (m_argc > 0 && m_argc < ARG_MAX) { // Reserve memory for argv m_argv = new const char * [m_argc]; if (!m_argv) { Logger::logError("Connection: reserving memory for argv"); return false; } // Get argv for (uint i = 0; i < m_argc; i++) { m_argv[i] = recvStr(); if (!m_argv[i]) { Logger::logError("Connection: receiving argv[%i]", i); return false; } } } else { Logger::logError("Connection: invalid number of parameters %d", m_argc); return false; } return true; }
void listener() { int channel,rcvid,returncode; msgpass * msg = malloc(sizeof(msgpass)); channel = makeChanP("/sys/taskbar"); while(1) { rcvid = recvMsg(channel,(void *)&msg); switch(msg->code) { case TSKM_KILLED: case TSKM_NEWITEM: case TSKM_MINIMIZED: case TSKM_INFOCUS: case TSKM_INBLUR: newThread(updateitem,STACK_DFL,msg); returncode = 0; break; case IO_OPEN: if(*(int *) (((char *)msg)+6) & (O_PROC|O_STAT)) returncode = makeCon(rcvid,1); else returncode = -1; break; } replyMsg(rcvid,returncode); } }
TEST_F(TrackerTest, runTCP) { t->_run = false; EXPECT_CALL(mockSocketTCP, attach()) .Times(1); EXPECT_CALL(mockSocketTCP, beginListen(1)) .Times(1); t->runTCP(); Mock::VerifyAndClearExpectations(&mockSocketTCP); t->_run = true; Client * c1 = new Client(&mockSocketTCP); Client * c2 = new Client(&mockSocketTCP); EXPECT_CALL(mockSocketTCP, attach()) .Times(1); EXPECT_CALL(mockSocketTCP, beginListen(1)) .Times(1); EXPECT_CALL(mockSocketTCP, recvMsg(_)) .WillOnce(Return(c1)) .WillOnce(Return(c2)) .WillOnce(Invoke(this,&TrackerTest::exitRunning)); t->runTCP(); EXPECT_EQ(t->_newClient.size(), 2); }
void tsClient :: startConnection() { while(true) { tv.tv_sec = 0; tv.tv_usec = SHORT_TIMER*1000; //time expire after short timer expiry tvptr = &tv; FD_ZERO(&master); master = read_fds; result = select( fd_max+1, &master, NULL, NULL, tvptr); ERROR(result==-1,__FILE__,__LINE__); if( FD_ISSET( sockId, & master) ) { recvMsg(); processMsg(); } else if(periodicTimer == true) { presentTime += SHORT_TIMER; updateNodePos(); if(presentTime == targetTime) //convert ns timer from sec to millisecond { //this is NS timer expiry, send update to NS makeSendMsg(NS_CONN); targetTime += timeInterval; } if(presentTime == dsTargetTime) { //this is dS timer expiry, send update to DS makeSendMsg(DS_CONN); dsTargetTime += dsTimeInterval; } } } close(sockId); }
void CM_TuneAndScan(void) { UINT32 retVal; MSG_TYPE_T msg; CM_TempInit(); while(1) { retVal = recvMsg(lQidCMChch, (void *)&msg, sizeof(msg), WAIT_FOREVER); switch(msg.typeA.msgID) { case MSG_PM2CM_NOTIFY_CH_INFO: { dbgprint("[CM_TuneAndScan] MSG_PM2CM_NOTIFY_CH_INFO received\n"); PSIP_GetChannelPacket(CH_PORT, PHYSICAL_CH_NUM, VSB_ANT, &gCmPacket); dbgprint("num of vch = %d\n",gCmPacket.numOfVCh); CM_TempSelectVch(0); break; } default: { break; } } } }
int redirect(int from, int to) { char buffer[DATA_SIZE]; int lost_connection; size_t bytes_read, bytes_written; lost_connection = 0; bytes_read = recvMsg(from, buffer); if (bytes_read == 0) { /*Connection Lost: cleanup*/ lost_connection = 1; memset(buffer, 0, sizeof buffer); } else { bytes_written = sendMsg(to, buffer); if (bytes_written == -1) { lost_connection = 1; memset(buffer, 0, sizeof buffer); } } return lost_connection; }
void ChatDialog::setupEventHandler() { QObject::connect(mBtnSend, SIGNAL(clicked()), this, SLOT(sendMsg())); QObject::connect(mBtnClose, SIGNAL(clicked()), this, SLOT(closeDialog())); QObject::connect(mChannel, SIGNAL(readyRead()), this, SLOT(recvMsg())); QObject::connect(mTxtSend, SIGNAL(textChanged()), this, SLOT(enableSendButton())); // QObject:: }
bool Connection::receiveActions() { Logger::logDebug("Connection: enter: %s", __FUNCTION__); while (1) { uint32_t action = 0; // Get the action. recvMsg(&action); switch (action) { case INVOKER_MSG_EXEC: receiveExec(); break; case INVOKER_MSG_ARGS: receiveArgs(); break; case INVOKER_MSG_ENV: // Clean-up all the env variables clearenv(); receiveEnv(); break; case INVOKER_MSG_PRIO: receivePriority(); break; case INVOKER_MSG_DELAY: receiveDelay(); break; case INVOKER_MSG_IO: receiveIO(); break; case INVOKER_MSG_IDS: receiveIDs(); break; case INVOKER_MSG_END: sendMsg(INVOKER_MSG_ACK); if (m_sendPid) sendPid(getpid()); return true; default: Logger::logError("Connection: received invalid action (%08x)\n", action); return false; } } }
void MainWindow::setupNewConn() { clientSocket = server->nextPendingConnection(); inputTextEdit->setDisabled(false); sendButton->setDisabled(false); setWindowTitle("Bump Chat! (A Client Connect!)"); connect(clientSocket, SIGNAL(readyRead()), this, SLOT(recvMsg())); connect(clientSocket, SIGNAL(disconnected()), this, SLOT(sockDisconnected())); }
void SocketServer::run() { #ifdef TCP // Start Listening for clients listen(sockfd, maxUser); logger->info("[INFO] SOCKET SERVER listening ..."); while (sockfd > 1) { //wait for clients Blocking Call connfd = accept(sockfd, (struct sockaddr *) &client_addr, (socklen_t *)&client_len); if (connfd < 1) { logger->error( "[ERROR] SOCKET SERVER Failed to accept connection."); close(connfd); } else { int result = send(connfd, buffer, sizeof(sendBuff) , 0); if (result < 0) logger->error("[ERROR] SOCKET SERVER Buffer Dispatch Error."); close(connfd); } } #else while (sockfd > 1 && getFlag() ) { //logger->info( "[INFO] SOCKET SERVER Ready to Receive"); //Blocking Call char* bufferRx = recvMsg(); std::thread recvThread( &SocketServer::receiveRequest, this , client_addr, bufferRx ); recvThread.detach(); //Sanity De-reference bufferRx=NULL; //Waiting Before Receiving another //std::unique_lock<std::mutex> lck(mtx); //cv.wait(lck); } #endif logger->info( "[INFO] SOCKET SERVER End Run"); }
void verifySignature(int sock,const byte *msg){ EVP_PKEY *skey = NULL, *vkey = NULL; int rc = make_keys(&skey, &vkey); assert(rc == 0); if(rc != 0) exit(1); assert(skey != NULL); if(skey == NULL) exit(1); assert(vkey != NULL); if(vkey == NULL) exit(1); byte* sig = NULL; size_t slen = 0; /* Using the skey or signing key */ rc = sign_it(msg, sizeof(msg), &sig, &slen, skey); assert(rc == 0); if(rc == 0) { printf("Created signature with length %d\n",(int)slen); } else { printf("Failed to create signature, return code %d\n", rc); exit(1); /* Should cleanup here */ } sendMsg(sock,"SendSignature"); while(strstr(recvMsg(sock),"SendSignature")==NULL){} sendMsg(sock,sig); byte* sig2 = NULL; sig2=recvMsg(sock); rc = verify_it(msg, sizeof(msg), sig2, sizeof(sig2), vkey); if(rc == 0) { printf("Verified signature. the length of sig is %d\n",(int)slen); } else { printf("length of recived signature is %d",(int)slen); printf("Failed to verify signature, return code %d\n", rc); } }
void test_recv (l2net_154 *l2) { Msg *in = initMsg(l2) ; l2_recv_t r ; printf("\n"); while ((r = recvMsg (in)) == RECV_OK) { printMsg (in) ; printf("\n"); } }
int StopNWait::recvMsgStream (MSG_TYPE *stream, int size) { ACK_TYPE rnext = 0; for (int i=0; i<size; i++) { if (!recvMsg(&stream[i], &rnext)) i--; } return 0; }
void MainWindow::addConnection() { QTcpSocket * s; s = server.nextPendingConnection(); stUserInfo user; user.pTcpSocket = s; list.append(user); connect(s,SIGNAL(disconnected()),this,SLOT(removeConnection())); connect(s,SIGNAL(readyRead()),this, SLOT(recvMsg())); ui->textEdit->append(QString("새로운 사용자입장")); }
void outThread(int *tlc) { FILE *stream; int RcvId; char *msg; char **upto; int count,type; int lastone=0; int ch; stream = fdopen(*tlc,"wb"); while (1) { RcvId = recvMsg(channel, (void *)&msg); type = * (int *)msg; if (type == SRVMSG) { count = * (int *)(msg+2); upto = (char **)(msg+4); while (count--) fputs(*upto++,stream); fprintf(stream,"\n"); fflush(stream); } else if (type == KEYINP) { ch = * (int *)(msg+2); if (ch == '\b' || ch == 0x7f) { putchar('\b'); putchar(' '); putchar('\b'); --inpx; } else { putchar(ch); ++inpx; } con_update(); } else if (type == CLRINP) { inpx=0; con_gotoxy(inpx,inpy); con_clrline(LC_End); con_update(); } else { con_gotoxy(0,22); if (lastone == SCRMSG) putchar('\n'); vprintf(* (char **)(msg+2), (void *)(msg+6)); lastone = type; con_gotoxy(inpx,inpy); con_update(); } replyMsg(RcvId,0); } }
int recvMsgBlock(communication * mycom, message **msg) { #ifdef DEBUGRECVMSGBLOCK printf("\n **** \n %zu reçois un message block\n **** \n", pthread_self()); #endif int ret; do { ret = recvMsg(mycom,msg); usleep(5000); } while(ret == NO_MSG); return ret; }
bool Connection::receiveEnv() { // Have some "reasonable" limit for environment variables to protect from // malicious data const uint32_t MAX_VARS = 1024; // Get number of environment variables. uint32_t n_vars = 0; recvMsg(&n_vars); if (n_vars > 0 && n_vars < MAX_VARS) { // Get environment variables for (uint32_t i = 0; i < n_vars; i++) { const char * var = recvStr(); if (var == NULL) { Logger::logError("Connection: receiving environ[%i]", i); return false; } // In case of error, just warn and try to continue, as the other side is // going to keep sending the reset of the message. // String pointed to by var shall become part of the environment, so altering // the string shall change the environment, don't free it if (putenv_sanitize(var)) { if (putenv_wrapper(const_cast<char *>(var)) != 0) { Logger::logWarning("Connection: putenv failed"); } } else { delete [] var; var = NULL; Logger::logWarning("Connection: invalid environment data"); } } } else { Logger::logError("Connection: invalid environment variable count %d", n_vars); return false; } return true; }
void main(int argc, char * argv[]) { int channel, rcvid, returncode; if(open("/sys/addressbook", O_PROC) != -1) { fprintf(stderr, "The addressbook service is already running.\n"); exit(EXIT_FAILURE); } xmlfile = XMLloadFile(fpathname("data/addressbook.xml", getappdir(), 1)); xmlelem = XMLgetNode(xmlfile, "xml"); channel = makeChanP("/sys/addressbook"); retexit(1); while(1) { rcvid = recvMsg(channel,(void *)&msg); switch(msg->code) { case GET_ATTRIB: returncode = getattrib(); break; case GET_ALL_LIST: returncode = getalllist(); break; case MAKE_ENTRY: returncode = makeentry(); break; case PUT_ATTRIB: returncode = putattrib(); break; case DEL_ENTRY: returncode = deleteentry(); break; case DEL_ATTRIB: returncode = deleteattrib(); break; case IO_OPEN: if(*(int *)( ((char*)msg) +6) & (O_PROC|O_STAT)) returncode = makeCon(rcvid, 1); else returncode = -1; break; } replyMsg(rcvid, returncode); } }
uint8_t HandleSockets::recvAllMsg() { uint8_t result = 0; for(int i = 0; i < MAX_NBR_OF_SOCKETS; i++) // Loop sockets { if(socketConnectionList[i] != SOCKET_NOT_CONNECTED) // Connected? { messagesIn[i] = recvMsg(socketConnectionList[i]); result = 1; } else { // Not connected messagesIn[i] = EMPTY_STR; } } return result; }
uint32_t Connection::receiveMagic() { uint32_t magic = 0; // Receive the magic. recvMsg(&magic); if ((magic & INVOKER_MSG_MASK) == INVOKER_MSG_MAGIC) { if (!((magic & INVOKER_MSG_MAGIC_VERSION_MASK) == INVOKER_MSG_MAGIC_VERSION)) { Logger::logError("Connection: receiving bad magic version (%08x)\n", magic); return -1; } } m_sendPid = magic & INVOKER_MSG_MAGIC_OPTION_WAIT; return magic & INVOKER_MSG_MAGIC_OPTION_MASK; }
int MyDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDialog::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: enter(); break; case 1: showTime(); break; case 2: timeoutslot(); break; case 3: showPicture(); break; case 4: sendMsg(); break; case 5: recvMsg(); break; case 6: error(); break; default: ; } _id -= 7; } return _id; }
const char * Connection::recvStr() { if (!m_testMode) { // Get the size. uint32_t size = 0; const uint32_t STR_LEN_MAX = 4096; bool res = recvMsg(&size); if (!res || size == 0 || size > STR_LEN_MAX) { Logger::logError("Connection: string receiving failed in %s, string length is %d", __FUNCTION__, size); return NULL; } char * str = new char[size]; if (!str) { Logger::logError("Connection: mallocing in %s", __FUNCTION__); return NULL; } // Get the string. uint32_t ret = read(m_fd, str, size); if (ret < size) { Logger::logError("Connection: getting string, got %u of %u bytes", ret, size); delete [] str; return NULL; } str[size - 1] = '\0'; Logger::logDebug("Connection: %s: '%s'", __FUNCTION__, str); return str; } else { return NULL; } }
string Connection::receiveAppName() { uint32_t msg = 0; // Get the action. recvMsg(&msg); if (msg != INVOKER_MSG_NAME) { Logger::logError("Connection: receiving invalid action (%08x)", msg); return string(); } const char* name = recvStr(); if (!name) { Logger::logError("Connection: receiving application name"); return string(); } string appName(name); delete [] name; return appName; }
int transfer(int from, int to, struct sockaddr_storage their_addr, socklen_t addr_len, struct sockaddr* res) { char buf[MAXDATASIZE]; int disconnected = 0; char s[INET6_ADDRSTRLEN]; size_t bytes_read; bytes_read = recvMsg(to, buf); printf("listener: got connection from %s\n", inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr), s, sizeof s)); if (bytes_read == 0) { disconnected = 1; memset(buf, 0, sizeof buf); } if(sendMessageUDP2(from, buf, res, addr_len) == -1) { disconnected = 1; memset(buf, 0, sizeof buf); } /*else { bytes_written = recvMsg(to, buf); if (bytes_written == -1) { disconnected = 1; memset(buf, 0, sizeof buf); } if ((numbytes = recvfrom(from, buf, MAXDATASIZE-1 , 0, res, &addr_len)) == -1) { perror("recvfrom"); exit(1); } }*/ return disconnected; }