Example #1
0
void irc_handle_connect(connection_t *cptr)
{
	/* add our server */
	{
		cptr->flags = CF_UPLINK;
		cptr->recvq_handler = irc_recvq_handler;
		connection_setselect_read(cptr, recvq_put);
		slog(LG_INFO, "irc_handle_connect(): connection to uplink established");
		me.connected = true;
		/* no SERVER message received */
		me.recvsvr = false;


		server_login();

#ifdef HAVE_GETTIMEOFDAY
		/* start our burst timer */
		s_time(&burstime);
#endif

		/* done bursting by this time... */
		ping_sts();

		/* ping our uplink every 5 minutes */
		if (ping_uplink_timer != NULL)
			mowgli_timer_destroy(base_eventloop, ping_uplink_timer);

		ping_uplink_timer = mowgli_timer_add(base_eventloop, "ping_uplink", ping_uplink, NULL, 300);

		me.uplinkpong = time(NULL);
	}
}
Example #2
0
/*服务端接收客户端命令,并进行解析,处理完毕返回0,返回1说明该套结字断开连接*/
int server_recv (struct pollfd  *poll_fd)
{
    struct cmd  cmdtemp ;
    struct link_list  *link_list_ptemp = NULL ;
    struct online_list  *online_list_ptemp = NULL ;
    int recv_len = 0 ;
    memset (&cmdtemp, 0, sizeof (struct cmd)) ;printf ("i get a bag\n") ;
    /*接收命令包*/
    if((recv_len = recv (poll_fd -> fd, &cmdtemp,  sizeof (struct cmd), 0)) < 0) {
        close (poll_fd -> fd) ;
        my_err ("recv", __LINE__) ;
        return -1 ;
    }
    /*如果该套结字断开连接,返回1则提示该套结字断开连接*/
    else if(recv_len == 0) {
        printf ("a client quit\n") ;
        /*从连接链表和在线用户链表中查找此套结字描述符,删去该结点*/
        if((link_list_ptemp = link_list_discover (link_list_PHEAD, poll_fd -> fd)) != NULL) {
            link_list_PHEAD = link_list_del (link_list_PHEAD, link_list_ptemp) ;
        }
        else if((online_list_ptemp = online_list_discover (online_list_PHEAD, poll_fd -> fd)) != NULL) {
            online_list_PHEAD = online_list_del (online_list_PHEAD, online_list_ptemp) ;
        }
        close (poll_fd -> fd) ;
        return 1 ;
    }
    /*接收正常的命令包,对其进行解析*/
    else {
        switch(cmdtemp.cmd_flag) {
            case MESSAGE :
                if(server_send (&cmdtemp) < 0) {
                    return -1 ;
                }
                break ;
            case LOGIN :
                if(server_login (poll_fd -> fd, &cmdtemp) <= 0) {
                    return -1 ;
                }
                printf ("login end \n") ;
                break ;
            case REGISTER :
                if(server_register (&cmdtemp, poll_fd -> fd) < 0) {
                    return -1 ;
                }
                break ;
            default :
                break ;
        }
        return 0 ;
    }
}