summaryrefslogtreecommitdiff
path: root/vchat-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-client.c')
-rwxr-xr-xvchat-client.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/vchat-client.c b/vchat-client.c
index c80e374..b7f993c 100755
--- a/vchat-client.c
+++ b/vchat-client.c
@@ -44,6 +44,8 @@ int status = 1;
44int ownquit = 0; 44int ownquit = 0;
45/* we set this, we DONT want to quit */ 45/* we set this, we DONT want to quit */
46int wantreconnect = 0; 46int wantreconnect = 0;
47static int reconnect_delay = 6;
48static time_t reconnect_time = 0;
47 49
48/* error string to show after exit */ 50/* error string to show after exit */
49char errstr[ERRSTRSIZE] = "\0"; 51char errstr[ERRSTRSIZE] = "\0";
@@ -65,7 +67,7 @@ static void parsecfg(char *line) {
65 char *param=line; 67 char *param=line;
66 char *value=NULL; 68 char *value=NULL;
67 69
68 /* handle quotes value is empty, so wecan use it */ 70 /* handle quotes value is empty, so we can use it */
69 value = strchr(line,'#'); 71 value = strchr(line,'#');
70 if (value) { /* the line contains a cute little quote */ 72 if (value) { /* the line contains a cute little quote */
71 value[0]='\0'; /* ignore the rest of the line */ 73 value[0]='\0'; /* ignore the rest of the line */
@@ -414,7 +416,8 @@ void calleverysecond( void ) {
414 quitrequest--; 416 quitrequest--;
415 if(outputcountdown && !--outputcountdown) 417 if(outputcountdown && !--outputcountdown)
416 hideout( ); 418 hideout( );
417 419 if( reconnect_time && ( time( NULL ) > reconnect_time ) )
420 status = 0;
418} 421}
419 422
420/* this function is called in the master loop */ 423/* this function is called in the master loop */
@@ -425,33 +428,33 @@ eventloop (void)
425 fd_set readfds = masterfds; 428 fd_set readfds = masterfds;
426 struct timeval tv = { 1, 0}; 429 struct timeval tv = { 1, 0};
427 430
428 switch (select (serverfd + 1, &readfds, NULL, NULL, &tv)) 431 switch (select (serverfd + 2, &readfds, NULL, NULL, &tv))
429 { 432 {
430 case -1: 433 case -1:
431 /* EINTR is most likely a SIGWINCH - ignore for now */ 434 /* EINTR is most likely a SIGWINCH - ignore for now */
432 if (errno != EINTR) 435 if (errno != EINTR)
433 { 436 {
434 snprintf (tmpstr, TMPSTRSIZE, "Select fails, %s.", strerror(errno)); 437 snprintf (tmpstr, TMPSTRSIZE, "Select fails, %s.", strerror(errno));
435 strncpy(errstr,tmpstr,TMPSTRSIZE-2); 438 strncpy(errstr,tmpstr,TMPSTRSIZE-2);
436 errstr[TMPSTRSIZE-2] = '\0'; 439 errstr[TMPSTRSIZE-2] = '\0';
437 strcat(errstr,"\n"); 440 strcat(errstr,"\n");
438 writecf (FS_ERR,tmpstr); 441 writecf (FS_ERR,tmpstr);
439 /* see this as an error condition and bail out */ 442 /* see this as an error condition and bail out */
440 status = 0; 443 status = 0;
441 } 444 }
442 break; 445 break;
443 case 0: 446 case 0:
444 /* time out reached */ 447 /* time out reached */
445 calleverysecond(); 448 calleverysecond();
446 break; 449 break;
447 default: 450 default:
448 /* something to read from user & we're logged in or have a cert? */ 451 /* something to read from user & we're logged in or have a cert? */
449 if (FD_ISSET (0, &readfds) && loggedin) 452 if (FD_ISSET (0, &readfds) )
450 userinput (); 453 userinput ();
451 454
452 /* something to read from server? */ 455 /* something to read from server? */
453 if (FD_ISSET (serverfd, &readfds)) 456 if (serverfd!=-1 && FD_ISSET (serverfd, &readfds))
454 networkinput (); 457 networkinput ();
455 break; 458 break;
456 } 459 }
457} 460}
@@ -495,7 +498,7 @@ main (int argc, char **argv)
495#endif 498#endif
496 499
497 switch (pchar) { 500 switch (pchar) {
498 case -1 : cmdsunparsed = 0; break; 501 case -1 : cmdsunparsed = 0; break;
499 case 'C': loadconfig(optarg); break; 502 case 'C': loadconfig(optarg); break;
500 case 'F': setstroption(CF_FORMFILE,optarg); break; 503 case 'F': setstroption(CF_FORMFILE,optarg); break;
501 case 'l': setintoption(CF_USESSL,0); break; 504 case 'l': setintoption(CF_USESSL,0); break;
@@ -528,21 +531,30 @@ main (int argc, char **argv)
528 initui (); 531 initui ();
529 532
530 while( status ) { 533 while( status ) {
534 /* add stdin to masterfds */
535 FD_ZERO (&masterfds);
536 FD_SET (0, &masterfds);
537
531 /* attempt connection */ 538 /* attempt connection */
532 if (!vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) { 539 if (vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) {
533 snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", 540 snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", strerror(errno));
534 strerror(errno)); 541 strncpy(errstr,tmpstr,TMPSTRSIZE-2);
535 strncpy(errstr,tmpstr,TMPSTRSIZE-2); 542 errstr[TMPSTRSIZE-2] = '\0';
536 errstr[TMPSTRSIZE-2] = '\0'; 543 strcat(errstr,"\n");
537 strcat(errstr,"\n"); 544 writecf (FS_ERR,tmpstr);
538 writecf (FS_ERR,tmpstr); 545
539 /* exit condition */ 546 if( getintoption( CF_AUTORECONN ) ) {
540 status = 0; 547 snprintf (tmpstr, TMPSTRSIZE, "reconnecting in %d seconds", reconnect_delay );
548 writecf (FS_ERR, tmpstr);
549 reconnect_delay = ( reconnect_delay * 15 ) / 10;
550 reconnect_time = time( NULL ) + reconnect_delay;
551 } else
552 status = 0;
541 } else { 553 } else {
542 /* add stdin & server to masterdfs */ 554 /* add serverfd to masterfds, reset reconnect delay */
543 FD_ZERO (&masterfds);
544 FD_SET (0, &masterfds);
545 FD_SET (serverfd, &masterfds); 555 FD_SET (serverfd, &masterfds);
556 reconnect_delay = 6;
557 reconnect_time = 0;
546 } 558 }
547 559
548 while (status) 560 while (status)