RaspberrPi project source code
guowenxue
2024-04-11 69b42a43ca4b2d93be203c34f6b45f5de1e32a15
project/socketd/sock_client.c
@@ -69,7 +69,9 @@
    char                 pack_buf[1024];
    int                  pack_bytes = 0;
    pack_info_t          pack_info;
    pack_proc_t          pack_proc = packet_segmented_pack; /* use string packet */
    pack_proc_t          pack_proc = packet_segmented_pack; /* use segmented string packet */
  //pack_proc_t          pack_proc = packet_json_pack;      /* use JSON string packet */
  //pack_proc_t          pack_proc = packet_tlv_pack;       /* use TLV(Tag Length Value) packet */
    struct option opts[] = {
        {"ipaddr", required_argument, NULL, 'i'},
@@ -180,25 +182,15 @@
         * +---------------------------------+*/
        /* start connect to server if not connected */
        if( sock.fd < 0 )
        if( !socket_connected(&sock) )
        {
            socket_connect(&sock);
        }
        /* check socket connected or not  */
        if( sock_check_connect(sock.fd) < 0 )
        {
            if( sock.fd > 0 )
            {
                log_error("socket got disconnected, terminate it and reconnect now.\n");
                socket_term(&sock); /* close the soket */
            }
        }
        /* +-------------------------------+
         * |      socket disconnect        |
         * +-------------------------------+*/
        if( sock.fd < 0 )
        if( !socket_connected(&sock) )
        {
            if( sample_flag )
            {
@@ -220,7 +212,7 @@
            {
                log_warn("socket send sample packet failure, save it in database now.\n");
                database_push_packet(pack_buf, pack_bytes);
                socket_term(&sock); /* close the soket */
                continue;
            }
        }
@@ -231,7 +223,7 @@
            if( socket_send(&sock, pack_buf, pack_bytes) < 0 )
            {
                log_error("socket send database packet failure");
                socket_term(&sock); /* close the soket */
                continue;
            }
            else
            {
@@ -240,7 +232,7 @@
            }
        }
        msleep(50);
        msleep(5);
    }
cleanup:
@@ -259,7 +251,7 @@
    time(&now);
    if( now >= *last_time+interval )
    if( difftime(now, *last_time)>interval )
    {
        need = 1; /* need sample now  */
        *last_time = now;