int ringqPutStrA(ringq_t *rq, char *str) { int rc; a_assert(rq); a_assert(str); a_assert(rq->buflen == (rq->endbuf - rq->buf)); rc = ringqPutBlk(rq, (unsigned char*) str, strlen(str)); rq->endp[0] = '\0'; return rc; }
int ringqPutStr(ringq_t *rq, char_t *str) { int rc; a_assert(rq); a_assert(str); a_assert(rq->buflen == (rq->endbuf - rq->buf)); rc = ringqPutBlk(rq, (unsigned char*) str, gstrlen(str) * sizeof(char_t)); *((char_t*) rq->endp) = (char_t) '\0'; return rc; }
int socketWrite(int sid, char *buf, int bufsize) { socket_t *sp; ringq_t *rq; int len, bytesWritten, room; a_assert(buf); a_assert(bufsize >= 0); if ((sp = socketPtr(sid)) == NULL) { return -1; } /* * Loop adding as much data to the output ringq as we can absorb. Initiate a * flush when the ringq is too full and continue. Block in socketFlush if the * socket is in blocking mode. */ rq = &sp->outBuf; for (bytesWritten = 0; bufsize > 0; ) { if ((room = ringqPutBlkMax(rq)) == 0) { if (socketFlush(sid) < 0) { return -1; } if ((room = ringqPutBlkMax(rq)) == 0) { if (sp->flags & SOCKET_BLOCK) { #if (defined (WIN) || defined (CE)) int errCode; if (! socketWaitForEvent(sp, FD_WRITE | SOCKET_WRITABLE, &errCode)) { return -1; } #endif continue; } break; } continue; } len = min(room, bufsize); ringqPutBlk(rq, (unsigned char *) buf, len); bytesWritten += len; bufsize -= len; buf += len; } return bytesWritten; }