- allow scriptcontext objects to be dynamic
- enhancements in scriptcontext (error messages stored as properties)
This commit is contained in:
53
network.c
53
network.c
@ -51,6 +51,8 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "sics.h"
|
||||
#include "commandlog.h"
|
||||
#include "uselect.h"
|
||||
|
||||
#define PORT 1
|
||||
@ -65,11 +67,6 @@ struct timeval lastclose = { -1, 0 };
|
||||
/*-----------------------------------------------------------------------
|
||||
Redefine this function if another means of error reporting is necessary.
|
||||
*/
|
||||
#include "Scommon.h"
|
||||
extern void SICSLogWrite(char *pText, OutCode eCode); /* servlog.c */
|
||||
|
||||
void WriteToCommandLog(char *p, char *t);
|
||||
|
||||
static void NetError(char *pText)
|
||||
{
|
||||
/*
|
||||
@ -674,8 +671,44 @@ int NETReadTillTerm(mkChannel * self, long timeout,
|
||||
status = NETAvailable(self, timeout - dif);
|
||||
};
|
||||
};
|
||||
assert(bufPtr > 0);
|
||||
return bufPtr;
|
||||
return status;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int NETReadRemob(mkChannel * self, long timeout, long timeout2,
|
||||
char term, char *pBuffer, int iBufLen)
|
||||
{
|
||||
struct timeval start, now;
|
||||
int bufPtr = 0, status, i, length, matchIndex = 1;
|
||||
char c;
|
||||
long dif;
|
||||
|
||||
if (!VerifyChannel(self)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(pBuffer, 0, iBufLen);
|
||||
|
||||
status = NETAvailable(self, timeout);
|
||||
while (status > 0) {
|
||||
status = recv(self->sockid, &c, 1, 0);
|
||||
if (status <= 0) {
|
||||
return status;
|
||||
}
|
||||
if (c == term) {
|
||||
return bufPtr + 1;
|
||||
}
|
||||
if (bufPtr >= iBufLen - 1) {
|
||||
return -1; /* overflow */
|
||||
}
|
||||
pBuffer[bufPtr] = c;
|
||||
bufPtr++;
|
||||
/*
|
||||
wait for more data
|
||||
*/
|
||||
status = NETAvailable(self, timeout2);
|
||||
};
|
||||
return status;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -701,7 +734,7 @@ int NETClosePort(mkChannel * self)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int NETReconnectWithFlags(mkChannel * self, int flags)
|
||||
{
|
||||
int iRet;
|
||||
int iRet = 0;
|
||||
int sock;
|
||||
int oldopts;
|
||||
|
||||
@ -709,7 +742,9 @@ int NETReconnectWithFlags(mkChannel * self, int flags)
|
||||
* Get the flags and close the old socket
|
||||
*/
|
||||
oldopts = fcntl(self->sockid, F_GETFL, 0);
|
||||
close(self->sockid);
|
||||
if (self->sockid != 0) {
|
||||
close(self->sockid);
|
||||
}
|
||||
/* Reopen and try to get it on the olf fd */
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (self->sockid != sock) {
|
||||
|
Reference in New Issue
Block a user