This commit is contained in:
cvs
2000-04-10 14:33:07 +00:00
parent c70f0b7cb8
commit d4974b94e8
11 changed files with 236 additions and 164 deletions

View File

@@ -101,9 +101,70 @@ int CocTryCmd(CocConn *conn)
/*-------------------------------------------------------------------------*/
int CocCmd(CocConn *conn, const char *rwList)
{ int iret, cnt, setmode, i;
int CocCmdWithRetry(CocConn *conn) {
int cnt, iret;
char *err;
cnt=3;
while (1) {
cnt--;
if (cnt<=0) {
ERR_I(CocTryCmd(conn));
break;
}
iret=CocTryCmd(conn);
if (iret>=0) break;
close(conn->fd);
conn->fd=-1;
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
ErrWrite("try again, error was");
}
ERR_P(err=str_get_str(conn->resbuf, NULL));
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
return(0);
OnError: return(-1);
}
/*-------------------------------------------------------------------------*/
int CocSet(CocConn *conn, const char *name, const char *value) {
assert(conn!=NULL);
str_put_start(conn->cmdbuf);
ERR_I(str_put_str(conn->cmdbuf, "["));
ERR_I(str_put_str(conn->cmdbuf, name));
ERR_I(str_put_str(conn->cmdbuf, value));
ERR_I(str_put_str(conn->cmdbuf, "]"));
ERR_I(CocCmdWithRetry(conn));
ERR_I(str_get_end(conn->resbuf));
return(0);
OnError: return(-1);
}
/*-------------------------------------------------------------------------*/
int CocGetN(CocConn *conn, const char *name, char *value, int reslen) {
assert(conn!=NULL);
str_put_start(conn->cmdbuf);
ERR_I(str_put_str(conn->cmdbuf, name));
ERR_I(CocCmdWithRetry(conn));
ERR_P(str_nget_str(conn->resbuf, value, reslen));
ERR_I(str_get_end(conn->resbuf));
return(0);
OnError: return(-1);
}
/*-------------------------------------------------------------------------*/
int CocCmd(CocConn *conn, const char *rwList)
{ int setmode, i;
const char *t, *s;
char nam[32];
CocVar *var;
@@ -137,22 +198,7 @@ int CocCmd(CocConn *conn, const char *rwList)
s=t+1;
} while (*t!='\0');
cnt=3;
while (1) {
cnt--;
if (cnt<=0) {
ERR_I(CocTryCmd(conn));
break;
}
iret=CocTryCmd(conn);
if (iret>=0) break;
close(conn->fd);
conn->fd=-1;
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
ErrWrite("try again, error was");
}
ERR_P(err=str_get_str(conn->resbuf, NULL));
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
ERR_I(CocCmdWithRetry(conn));
/* read values */
s=rwList;