示例#1
0
void tcp_input( ITEM *listItem ) {
	TCP_NODE *n = list_value( listItem );
	char buffer[BUF_SIZE];
	ssize_t bytes = 0;
	
	while( status == RUMBLE ) {

		/* Reset timeout counter */
		node_activity( n );
		
		/* Get data */
		bytes = recv( n->connfd, buffer, BUF_OFF1, 0 );

		if( bytes < 0 ) {
			if( errno == EAGAIN || errno == EWOULDBLOCK ) {
				return;
			} else if( errno == ECONNRESET ) {
				/*
				 * Very common behaviour
				 * info( &n->c_addr, 0, "Connection reset by peer" );
				 */
				node_status( n, NODE_MODE_SHUTDOWN );
				return;
			} else {
				info( &n->c_addr, 0, "recv() failed:" );
				info( &n->c_addr, 0, strerror( errno ) );
				return;
			}
		} else if( bytes == 0 ) {
			/* Regular shutdown */
			node_status( n, NODE_MODE_SHUTDOWN );
			return;
		} else {
			/* Read */
			tcp_buffer( n, buffer, bytes );
			return;
		}
	}
}
示例#2
0
static int
qltcp_outbuf(lua_State *state) {
  return tcp_buffer(state, 0);
}
示例#3
0
static int
qltcp_inbuf(lua_State *state) {
  return tcp_buffer(state, 1);
}