예제 #1
0
int
smbc_closedir(int dh) 
{
	SMBCFILE * file = find_fd(dh);
	del_fd(dh);
        return smbc_getFunctionClosedir(statcont)(statcont, file);
}
예제 #2
0
void Poll_t::handle_data()
{
    for(int i = 1; i <= maxi_; ++i)
    {
        int peerfd = client_[i].fd;
        if(client_[i].fd == -1)
            continue;
        if(client_[i].revents & POLLIN)
        {
            char buf[1024] = {0};
            int ret = readline(peerfd, buf, 1024);
            if(ret == -1)
            {
                ERR_EXIT("readline");
            }
            else if(ret == 0)
            {
                std::cout << "client close " << std::endl;
                del_fd(i);
                continue;
            }
            printf("%s\n",buf);
            callback_(peerfd, buf);
        } 
    }
}
예제 #3
0
int
smbc_close(int fd)
{
	SMBCFILE * file = find_fd(fd);
	del_fd(fd);
        return smbc_getFunctionClose(statcont)(statcont, file);
}
예제 #4
0
파일: ui.c 프로젝트: bob-linuxtoys/eedd
/***************************************************************************
 * close_ui_conn(): - Close an existing UI conn.
 *
 * Input:        Index of conn to close
 * Output:       void
 * Effects:      manager connection table (ui)
 ***************************************************************************/
void close_ui_conn(int cn)
{
    close(UiCons[cn].fd);
    del_fd(UiCons[cn].fd);
    UiCons[cn].fd = -1;
    nui--;
    listen(srvfd, MX_UI - nui);  //  lower the number of avail conns
    return;
}
예제 #5
0
파일: ui.c 프로젝트: bob-linuxtoys/eedd
/***************************************************************************
 * receive_ui(): - This routine is called to read data
 * from a TCP connection.  We look for an end-of-line and pass
 * full lines to the CLI parser.  
 *
 * Input:        FD of socket with data to read
 * Output:       void
 * Effects:      the Baseboard vie the CLI parser
 ***************************************************************************/
void receive_ui(int fd_in, int cb_data)
{
    int      nrd;            /* number of bytes read */
    int      i;              /* a temp int */
    int      gotline;        /* set true if we get a full line */
    int      cn;             /* index into UiCons */
    UI      *pui;            /* pointer to UI at cn */

    /* Locate the UI struct with fd equal to fd_in */
    for (cn = 0 ; cn < MX_UI; cn++) {
        if (fd_in == UiCons[cn].fd) {
            break;
        }
    }
    /* Error if we could not find the fd */
    if (MX_UI == cn) {
        /* Take this bogus fd out of the select loop */
        del_fd(fd_in);
        close(fd_in);
        return;
    }
    pui = &(UiCons[cn]);

    /* We read data from the connection into the buffer in the ui struct. Once
     * we've read all of the data we can, we scan for a newline character and
     * pass any full lines to the parser. */
    nrd = read(pui->fd, &(pui->cmd[pui->cmdindx]), (MXCMD - pui->cmdindx));

    /* shutdown manager conn on error or on zero bytes read */
    if ((nrd <= 0) && (errno != EAGAIN)) {
        close_ui_conn(cn);
        return;
    }

    pui->cmdindx += nrd;

    /* The commands are in the buffer. Call the parser to execute them */
    do {
        gotline = 0;
        // Scan for a newline.    If found, replace it with a null
        for (i = 0; i < pui->cmdindx; i++) {
            if (pui->cmd[i] == '\n') {
                pui->cmd[i] = (char) 0;
                gotline = 1;
                parse_and_execute(pui);
                (void) memmove(pui->cmd, &(pui->cmd[i+1]), (pui->cmdindx - (i+1)));
                pui->cmdindx -= i+1;
                break;
            }
        }
    } while ((gotline == 1) && (pui->cmdindx > 0));

    return;
}
예제 #6
0
파일: c_basis.cpp 프로젝트: Mignet/zstorage
void c_basis::erase_socket( int32 fd )
{
	m_mSocket.erase(fd);

	del_fd(fd);
}
예제 #7
0
파일: trans.c 프로젝트: lanxbrad/sec-fw
void server_run(void)
{
	fd_set trfds;
	int retval, ret, i;
	int conn_fd;
	struct sockaddr_in addr;
	struct timeval tv;
	uint8_t buf_r[1518];
	uint32_t length;

	while(1)
	{
		trfds = rfds;
		tv.tv_sec = 0;
		tv.tv_usec = 500;
		
		retval = select(maxfd + 1, &trfds, NULL, NULL, &tv);
		if(-1 == retval)
		{
			LOG("select error\n");
		}
		else if(0 == retval)
		{
			/*timeout*/
		}
		else 
		{
			/* process tcp client request */
			if (FD_ISSET(listenfd, &trfds))
			{
				LOG("connect input\n");
				memset((void *)&addr, 0, sizeof(addr));
				length = sizeof(addr);
				conn_fd = accept(listenfd, (struct sockaddr *)&addr, &length);
				if(conn_fd > 0)
				{
					add_fd(TCP_CLIENT, conn_fd, &addr);
					g_client_connect_num++;
					LOG("new client %d connected whose ip=%s port=%d\n",
							conn_fd, inet_ntoa(addr.sin_addr), addr.sin_port);
					current_sock_fd = conn_fd;
				}
			}

			for (i = 3; i < SOCK_MAX; i++) 
			{
				if (sock_map[i].status == INVALID)
				{
					continue;
				}
				if (FD_ISSET(i, &trfds)) 
				{
					
					LOG("socket %d has data,type=%d\n", i, sock_map[i].sock_type);
					switch (sock_map[i].sock_type)
					{
						/* process tcp request */
						case TCP_CLIENT:
						{
							ret = recv_tcp_client_packet(i, buf_r, &length);
							current_sock_fd = i;
							if (ret == 0) 
							{
								//dump_packet(buf_r, length);
								ret = tcp_client_message_handle(buf_r, length, i);
							} else 
								LOG("tcpserver socket recv length is less\n" );
							break;
						}
						default:
						{
							LOG("select unknow socket type = %d\n", sock_map[i].sock_type);
							break;
						}
					}
					/*
			              *  if some rcpclient close the connect, clean up some resource 
			              */
					if (length <= 0) {
						if (sock_map[i].sock_type == TCP_CLIENT) 
						{
							close(i);
							del_fd(i);
							LOG("%d socket del\n", i);
						}
					}
				}
			}
		}
	}
}