rem: DBG("************* before select\n");
context: void *do_receive(void *arg){	struct list_head    *lh;	struct list_head    peers;	struct thread_info  *tinfo;	struct peer         *p;	fd_set ret_rd_set;	fd_set ret_wr_set;	int option;	int length;	int nready;	int ncmd;	struct command cmd;	/* init section */	tinfo = (struct thread_info*)arg;	FD_ZERO( &(tinfo->rd_set) );	FD_ZERO( &(tinfo->wr_set) );	INIT_LIST_HEAD( &peers );	/* add command pipe for listening */	FD_SET( tinfo->cmd_pipe[0] , &tinfo->rd_set);	while(1) {		ret_rd_set = tinfo->rd_set;		ret_wr_set = tinfo->wr_set;		DBG("************* before select\n");		nready = select( FD_SETSIZE+1, &ret_rd_set, &ret_wr_set, 0, 0);		DBG("************* after select (%d)\n",nready);		if (nready == -1) {			if (errno == EINTR) {				continue;			} else {				LOG(L_ERR,"ERROR:do_receive: dispatcher call to select fails:"					" %s\n", strerror(errno));				sleep(2);				continue;			}		}		/*no timeout specified, therefore must never get into this if*/		if (nready == 0)			assert(0);		if ( FD_ISSET( tinfo->cmd_pipe[0], &ret_rd_set) ) {			/* read the command */			ncmd = read( tinfo->cmd_pipe[0], &cmd, COMMAND_SIZE);			if ( ncmd!=COMMAND_SIZE ){				if (ncmd==0) {					LOG(L_CRIT,"ERROR:do_receive: reading command "						"pipe -> it's closed!!\n");					goto error;				}else if (ncmd<0) {					LOG(L_ERR,"ERROR:do_receive: reading command "						"pipe -> %s\n",strerror(errno));				} else {					LOG(L_ERR,"ERROR:do_receive: reading command "						"pipe -> only %d\n",ncmd);				}			} else {				/* execute the command */				switch (cmd.code) {					case SHUTDOWN_CMD:						LOG(L_INFO,"INFO:do_receive: SHUTDOWN command "							"received-> closing peer\n");						//peer_state_machine( cmd.peer, PEER_HANGUP, 0);						return 0;						break;					case ADD_PEER_CMD:						LOG(L_INFO,"INFO:do_receive: adding new peer\n");						list_add_tail( &cmd.peer->thd_peer_lh, &peers);						cmd.peer->tinfo = tinfo;					case CONNECT_CMD:						LOG(L_INFO,"INFO:do_receive: connecting peer\n");						tcp_connect( cmd.peer );						break;					case ACCEPTED_CMD:						LOG(L_INFO,"INFO:do_receive: accept received\n");						tcp_accept( cmd.peer , cmd.fd);						break;					case TIMEOUT_PEER_CMD:						LOG(L_INFO,"INFO:do_receive: timeout received\n");						peer_state_machine( cmd.peer, cmd.fd, cmd.attrs);						break;					case INACTIVITY_CMD:						LOG(L_INFO,"INFO:do_receive: inactivity detected\n");						peer_state_machine( cmd.peer, PEER_IS_INACTIV, 0);						break;					case CLOSE_CMD:						LOG(L_INFO,"INFO:do_receive: close cmd. received\n");						peer_state_machine( cmd.peer, TCP_CONN_CLOSE, 0);						break;					default:						LOG(L_ERR,"ERROR:do_receive: unknown command "							"code %d -> ignoring command\n",cmd.code);				}			}			if (--nready==0)				continue;		}		list_for_each( lh, &peers) {			if (!nready)				break;			p = list_entry( lh, struct peer, thd_peer_lh);			if ( p->sock!=-1 && FD_ISSET( p->sock, &ret_rd_set) ) {				nready--;				/* data received */				if (do_read( p )==-1)					peer_state_machine( p, TCP_CONN_CLOSE, 0);				continue;			}			if ( p->sock!=-1 && FD_ISSET( p->sock, &ret_wr_set) ) {				nready--;				DBG("DEBUG:do_receive: connect done on socket %d\n",p->sock);				FD_CLR( p->sock, &tinfo->wr_set);				length = sizeof(option);				if ((ncmd=getsockopt( p->sock, SOL_SOCKET, SO_ERROR, &option,				&length))==-1 || option!=0 ) {					LOG(L_ERR,"ERROR:do_receive: getsockopt=%d ; res=%d\n",						ncmd, option);					close( p->sock );					peer_state_machine( p, TCP_CONN_FAILED, 0);				} else {					do_connect( p, p->sock);				}			}		}	}/*while*/error:	return 0;}