| | |
| | | int main(int argc, char **argv) |
| | | { |
| | | int rv = -1; |
| | | int pr_times = 0; |
| | | int port; |
| | | char *serverip; |
| | | int interval = 30; /* default report termperature every 30 seconds */ |
| | |
| | | /* set logger to $logfile with level info */ |
| | | if( logger_init(logfile, LOG_LEVEL_INFO) < 0 ) |
| | | { |
| | | fprintf(stderr, "Initial logger file '%s' failure: %s\n", strerror(errno)); |
| | | fprintf(stderr, "Initial logger file '%s' failure: %s\n", logfile, strerror(errno)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | /* start connect to server if not connected */ |
| | | if( sock.fd < 0 ) |
| | | { |
| | | if( 0 == (pr_times % 10) ) |
| | | { |
| | | log_info("socket not connect, start connect it now.\n"); |
| | | } |
| | | socket_connect(&sock); |
| | | } |
| | | |
| | | /* check socket connected or not */ |
| | | if( sock_check_connect(sock.fd) < 0 ) |
| | | { |
| | | pr_times ++; |
| | | if( 0 == (pr_times % 10) ) |
| | | if( sock.fd > 0 ) |
| | | { |
| | | log_error("socket got disconnected, terminate it and reconnect now.\n"); |
| | | pr_times = 0; |
| | | socket_term(&sock); /* close the soket */ |
| | | } |
| | | socket_term(&sock); /* close the soket */ |
| | | } |
| | | |
| | | /* socket disconnected */ |