Don't exit from reconnect mode if connection was denied.

This commit is contained in:
Max Krasnyansky 2002-07-23 19:51:11 +00:00
parent 6c76db6269
commit 89d41e2e6c

View File

@ -120,12 +120,14 @@ int do_connect(char *svr)
rem_addr.l2_psm = htobs(psm); rem_addr.l2_psm = htobs(psm);
if( connect(s, (struct sockaddr *)&rem_addr, sizeof(rem_addr)) < 0 ){ if( connect(s, (struct sockaddr *)&rem_addr, sizeof(rem_addr)) < 0 ){
syslog(LOG_ERR, "Can't connect. %s(%d)", strerror(errno), errno); syslog(LOG_ERR, "Can't connect. %s(%d)", strerror(errno), errno);
close(s);
return -1; return -1;
} }
opt = sizeof(opts); opt = sizeof(opts);
if( getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0 ){ if( getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0 ){
syslog(LOG_ERR, "Can't get L2CAP options. %s(%d)", strerror(errno), errno); syslog(LOG_ERR, "Can't get L2CAP options. %s(%d)", strerror(errno), errno);
close(s);
return -1; return -1;
} }
@ -305,11 +307,11 @@ void send_mode(int s)
buf[i]=0x7f; buf[i]=0x7f;
seq = 0; seq = 0;
while(1){ while (1) {
*(uint32_t *)buf = htobl(seq++); *(uint32_t *) buf = htobl(seq++);
*(uint16_t *)(buf+4) = htobs(data_size); *(uint16_t *)(buf+4) = htobs(data_size);
if( send(s, buf, data_size, 0) <= 0 ) { if (send(s, buf, data_size, 0) <= 0) {
syslog(LOG_ERR, "Send failed. %s(%d)", strerror(errno), errno); syslog(LOG_ERR, "Send failed. %s(%d)", strerror(errno), errno);
exit(1); exit(1);
} }
@ -318,14 +320,9 @@ void send_mode(int s)
void reconnect_mode(char *svr) void reconnect_mode(char *svr)
{ {
while(1){ while(1) {
int s; int s = do_connect(svr);
if( (s = do_connect(svr)) < 0 )
exit(1);
close(s); close(s);
usleep(10);
} }
} }
@ -337,19 +334,20 @@ void connect_mode(char *svr)
sleep(99999999); sleep(99999999);
} }
void multy_connect_mode(char *svr) void multi_connect_mode(char *svr)
{ {
while(1){ while (1) {
int i, s; int i, s;
for(i=0; i<10; i++){ for (i=0; i<10; i++) {
if( fork() ) continue; if (fork()) continue;
/* Child */ /* Child */
s = do_connect(svr); s = do_connect(svr);
usleep(500);
close(s); close(s);
exit(0); exit(0);
} }
sleep(19); sleep(2);
} }
} }
@ -517,7 +515,7 @@ int main(int argc ,char *argv[])
break; break;
case MULTY: case MULTY:
multy_connect_mode(argv[optind]); multi_connect_mode(argv[optind]);
break; break;
case CONNECT: case CONNECT: