BuildServer::BuildServer( QWidget *parent ) : QDialog( parent ) { label = new QLabel( QString::fromUtf8( "正在监听..." ) ) ; cancelPushButton = new QPushButton( QString::fromUtf8( "取消" ) , this ) ; connect( cancelPushButton , SIGNAL( clicked() ) , this , SLOT( cancelSlot() ) ) ; tableWidget = new QTableWidget( this ) ; tableWidget->setColumnCount( 2 ) ; tableWidget->setColumnWidth( 0 , 140 ); tableWidget->setColumnWidth( 1 , 140 ) ; tableWidget->setRowCount( 0 ) ; QStringList headers; headers << "HostName" << "IP" ; tableWidget->setHorizontalHeaderLabels( headers ) ; tableWidget->setEditTriggers( QTableWidget::NoEditTriggers ) ; tableWidget->setSelectionBehavior( QTableWidget::SelectRows ) ; tableWidget->setSelectionMode( QTableWidget::SingleSelection ) ; buttonLayout = new QHBoxLayout ; mainLayout = new QVBoxLayout ; buttonLayout->addStretch() ; buttonLayout->addWidget( cancelPushButton ) ; buttonLayout->addStretch() ; mainLayout->addWidget( label ) ; mainLayout->addWidget( tableWidget ) ; mainLayout->addLayout( buttonLayout ) ; setLayout( mainLayout ) ; setFixedSize( 300 , 300) ; connect( tableWidget , SIGNAL( itemClicked( QTableWidgetItem * ) ) , this , SLOT( onItemClicked ( QTableWidgetItem*) ) ) ; listen_udp() ; }
static struct chunkiser_ctx *udp_open(const char *fname, int *period, const char *config) { struct chunkiser_ctx *res; struct timeval tv; int i; const int *ports; res = malloc(sizeof(struct chunkiser_ctx)); if (res == NULL) { return NULL; } ports = ports_parse(config); if (ports[0] == -1) { free(res); return NULL; } for (i = 0; ports[i] >= 0; i++) { res->fds[i] = listen_udp(ports[i]); if (res->fds[i] < 0) { fprintf(stderr, "Cannot open port %d\n", ports[i]); for (; i>=0 ; i--) { close(res->fds[i]); } free(res); return NULL; } } res->fds[i] = -1; gettimeofday(&tv, NULL); res->start_time = tv.tv_usec + tv.tv_sec * 1000000ULL; res->id = 1; res->buff = NULL; res->size = 0; res->counter = 0; res->every = 1; *period = 0; return res; }
void listen_call_handler(unsigned long long uniqueSockID, int threads, unsigned char *buf, ssize_t len) { int index; int backlog; u_char *pt; PRINT_DEBUG(""); pt = buf; backlog = *(int *) pt; pt += sizeof(int); if (pt - buf != len) { PRINT_DEBUG("READING ERROR! CRASH, diff=%d len=%d", pt - buf, len); nack_send(uniqueSockID, listen_call); return; } PRINT_DEBUG(""); index = findjinniSocket(uniqueSockID); PRINT_DEBUG(""); if (index == -1) { PRINT_DEBUG( "CRASH !!! socket descriptor not found into jinni sockets SO pipe descriptor to reply is not found too "); nack_send(uniqueSockID, listen_call); return; } PRINT_DEBUG(""); if (jinniSockets[index].type == SOCK_DGRAM) listen_udp(uniqueSockID, backlog); else if (jinniSockets[index].type == SOCK_STREAM) listen_tcp(uniqueSockID, backlog); else if (jinniSockets[index].type == SOCK_RAW) { listen_icmp(uniqueSockID, backlog); } else { PRINT_DEBUG("unknown socket type has been read !!!"); nack_send(uniqueSockID, listen_call); } }