binkp_loop return codes

master
Sergey Dorofeev 13 years ago
parent 1c2f44fc3f
commit f2d9c6e4a7

@ -57,6 +57,7 @@ typedef struct {
e_file_receive_status frs; e_file_receive_status frs;
int emptyloop; int emptyloop;
bool continuesend; bool continuesend;
int rc;
} s_binkp_state; } s_binkp_state;
int binkp_getforsend(s_binkp_state *bstate, char *buf, int *block_type, unsigned short *block_length); int binkp_getforsend(s_binkp_state *bstate, char *buf, int *block_type, unsigned short *block_length);
@ -68,8 +69,7 @@ int binkp_loop(s_binkp_state *bstate) {
unsigned char readbuf[BINKP_HEADER+BINKP_MAXBLOCK+1]; unsigned char readbuf[BINKP_HEADER+BINKP_MAXBLOCK+1];
unsigned char writebuf[BINKP_HEADER+BINKP_MAXBLOCK+1]; unsigned char writebuf[BINKP_HEADER+BINKP_MAXBLOCK+1];
int rc = HRC_OK; bstate->rc = PRC_NOERROR;
bstate->phase = 0; bstate->phase = 0;
bstate->subphase = 0; bstate->subphase = 0;
bstate->extracmd[0] = -1; bstate->extracmd[0] = -1;
@ -133,7 +133,7 @@ int binkp_loop(s_binkp_state *bstate) {
writebuf[0] = (block_length>>8)&0x7f; writebuf[0] = (block_length>>8)&0x7f;
} else { } else {
log("block for sending has invalid type, aborting"); log("block for sending has invalid type, aborting");
return -1; return PRC_ERROR;
} }
writebuf[1] = block_length&0xff; writebuf[1] = block_length&0xff;
} }
@ -146,7 +146,7 @@ int binkp_loop(s_binkp_state *bstate) {
} }
if (m<0 || m>3) { if (m<0 || m>3) {
log("getforsend error"); log("getforsend error");
return -1; return PRC_ERROR;
} }
} }
@ -182,13 +182,13 @@ int binkp_loop(s_binkp_state *bstate) {
n = tty_select(want_read?&canread:NULL, have_to_write?&canwrite:NULL, timeout); n = tty_select(want_read?&canread:NULL, have_to_write?&canwrite:NULL, timeout);
if( n<0 ) { if( n<0 ) {
log("binkp error on tty_select"); log("binkp error on tty_select");
return -1; return PRC_ERROR;
} }
} }
else { else {
log("empty loop %d", ++bstate->emptyloop); log("empty loop %d", ++bstate->emptyloop);
if (bstate->emptyloop==10) { if (bstate->emptyloop==10) {
return -1; return PRC_ERROR;
} }
} }
@ -196,11 +196,11 @@ int binkp_loop(s_binkp_state *bstate) {
n = tty_read(readbuf+read_pos, want_read); n = tty_read(readbuf+read_pos, want_read);
if( n<0 ) { if( n<0 ) {
log("binkp: tty read error"); log("binkp: tty read error");
return -1; return PRC_ERROR;
} }
else if (n==0) { else if (n==0) {
log("read: remote socket shutdown"); log("read: remote socket shutdown");
return -1; return PRC_REMOTEABORTED;
} }
want_read -= n; want_read -= n;
read_pos += n; read_pos += n;
@ -234,11 +234,11 @@ int binkp_loop(s_binkp_state *bstate) {
else if (m==3) { else if (m==3) {
log("aborting session"); log("aborting session");
bstate->complete = true; bstate->complete = true;
rc = HRC_OTHER_ERR; //rc = HRC_OTHER_ERR;
} }
else { else {
log("doreceiveblock error"); log("doreceiveblock error");
return -1; return PRC_ERROR;
} }
} }
@ -247,18 +247,18 @@ int binkp_loop(s_binkp_state *bstate) {
n = tty_write(writebuf+write_pos, have_to_write); n = tty_write(writebuf+write_pos, have_to_write);
if( n<0 ) { if( n<0 ) {
log("binkp: tty write error"); log("binkp: tty write error");
return -1; return PRC_ERROR;
} }
else if (n==0) { else if (n==0) {
log("write: remote socket shutdown"); log("write: remote socket shutdown");
return -1; return PRC_REMOTEABORTED;
} }
//log("%d bytes sent", n); //log("%d bytes sent", n);
write_pos += n; write_pos += n;
have_to_write -= n; have_to_write -= n;
} }
} }
return rc; return bstate->rc;
} }
int binkp_outgoing(s_binkp_sysinfo *local_data, s_binkp_sysinfo *remote_data) int binkp_outgoing(s_binkp_sysinfo *local_data, s_binkp_sysinfo *remote_data)
@ -614,7 +614,8 @@ case 4:
} }
#define PROTO_ERROR(msg) log("error: %s", msg); bstate->extracmd[0] = BPMSG_ERR; strcpy(bstate->extracmd+1, msg); bstate->extraislast = true; return -1; #define PROTO_ERROR(msg) { log("error: %s", msg); bstate->rc = PRC_LOCALABORTED; \
bstate->extracmd[0] = BPMSG_ERR; strcpy(bstate->extracmd+1, msg); bstate->extraislast = true; return 1; }
int binkp_doreceiveblock(s_binkp_state *bstate, char *buf, int block_type, unsigned short block_length) int binkp_doreceiveblock(s_binkp_state *bstate, char *buf, int block_type, unsigned short block_length)
@ -897,9 +898,11 @@ check_that_all_files_are_confirmed:
case BPMSG_ERR: /* Misc errors */ case BPMSG_ERR: /* Misc errors */
log("remote error: %s", buf+1); log("remote error: %s", buf+1);
bstate->rc = PRC_REMOTEABORTED;
return 3; return 3;
case BPMSG_BSY: /* All AKAs are busy */ case BPMSG_BSY: /* All AKAs are busy */
log("remote busy: %s", buf+1); log("remote busy: %s", buf+1);
bstate->rc = PRC_REMOTEABORTED;
return 3; return 3;
case BPMSG_GET: /* Get a file from offset */ case BPMSG_GET: /* Get a file from offset */

@ -17,12 +17,12 @@
#include "outbound.h" #include "outbound.h"
/* File transfer protocols return codes */ /* File transfer protocols return codes */
#define PRC_NOERROR 0 /* No comments :) */ #define PRC_NOERROR 0 /* Successful session */
#define PRC_ERROR 1 /* I/O error occured while snd./rcv. */ #define PRC_ERROR 20 /* I/O error occured while snd./rcv. */
#define PRC_REMOTEABORTED 2 /* "ABORT" initiated by remote */ #define PRC_REMOTEABORTED 21 /* "ABORT" initiated by remote */
#define PRC_LOCALABORTED 3 /* We got SIGINT/SIGTERM? */ #define PRC_LOCALABORTED 22 /* We got SIGINT/SIGTERM? */
#define PRC_CPSTOOLOW 4 /* Cps was so low.. :( */ #define PRC_CPSTOOLOW 23 /* Cps was so low.. :( */
#define PRC_STOPTIME 5 /* Aborted due to the time limits */ #define PRC_STOPTIME 24 /* Aborted due to the time limits */
/* Send/Recv file status values */ /* Send/Recv file status values */
#define FSTAT_PROCESS 1 #define FSTAT_PROCESS 1

Loading…
Cancel
Save