void EvalXTCPRecv(const void *obj, qCtx *ctx, qStr *out, qArgAry *args) { Sock *s = (Sock *) obj; int len; char *line = NULL; if (args->Count() > 0) { len = ParseInt((*args)[0]); len = s->Read(len); line = s->GetBuf(); } else { len = s->ReadLine(&line); } if (len > 0) out->PutS(line, len); else if (len < 0 ) { if (len == Sock::ERR_TIMEOUT) { ctx->ThrowF(out, 702, "Timeout while waiting to read data from host %s:%d, %y", s->GetHost(), s->GetPort()); } else { ctx->ThrowF(out, 702, "Error while reading data from host %s:%d, %y", s->GetHost(), s->GetPort(), GetLastError()); } } }
void EvalXTCPSend(const void *obj, qCtx *ctx, qStr *out, qArgAry *args) { Sock *s = (Sock *) obj; CStr str = (*args)[0]; int len = s->Write(str, str.Length()); if (len < 0 ) { if (len == Sock::ERR_TIMEOUT) { ctx->ThrowF(out, 702, "Timeout while waiting to write data from host %s:%d, %y", s->GetHost(), s->GetPort()); } else { ctx->ThrowF(out, 702, "Error while writing data from host %s:%d, %y", s->GetHost(), s->GetPort(), GetLastError()); } } }