void socketSetBufferSize(int sid, int in, int line, int out) { socket_t *sp; if ((sp = socketPtr(sid)) == NULL) { return; } if (in >= 0) { ringqClose(&sp->inBuf); in++; ringqOpen(&sp->inBuf, in, in); } if (line >= 0) { ringqClose(&sp->lineBuf); line++; ringqOpen(&sp->lineBuf, line, line); } if (out >= 0) { ringqClose(&sp->outBuf); out++; ringqOpen(&sp->outBuf, out, out); } }
int socketAlloc(char *host, int port, socketAccept_t accept, int flags) { socket_t *sp; int sid; if ((sid = hAllocEntry((void***) &socketList, &socketMax, sizeof(socket_t))) < 0) { return -1; } sp = socketList[sid]; sp->sid = sid; sp->accept = accept; sp->port = port; sp->fileHandle = -1; sp->saveMask = -1; if (host) { strncpy(sp->host, host, sizeof(sp->host)); } /* * Preserve only specified flags from the callers open */ a_assert((flags & ~(SOCKET_BROADCAST|SOCKET_DATAGRAM|SOCKET_BLOCK| SOCKET_LISTENING)) == 0); sp->flags = flags & (SOCKET_BROADCAST | SOCKET_DATAGRAM | SOCKET_BLOCK | SOCKET_LISTENING | SOCKET_MYOWNBUFFERS); if (!(flags & SOCKET_MYOWNBUFFERS)) { /* * Add one to allow the user to write exactly SOCKET_BUFSIZ */ ringqOpen(&sp->inBuf, SOCKET_BUFSIZ, SOCKET_BUFSIZ); ringqOpen(&sp->outBuf, SOCKET_BUFSIZ + 1, SOCKET_BUFSIZ + 1); } else { memset(&sp->inBuf, 0x0, sizeof(ringq_t)); memset(&sp->outBuf, 0x0, sizeof(ringq_t)); } ringqOpen(&sp->lineBuf, SOCKET_BUFSIZ, -1); return sid; }
int ejLexOpenScript(ej_t* ep, char_t *script) { ejinput_t *ip; a_assert(ep); a_assert(script); if ((ep->input = balloc(B_L, sizeof(ejinput_t))) == NULL) { return -1; } ip = ep->input; memset(ip, 0, sizeof(*ip)); a_assert(ip); a_assert(ip->putBackToken == NULL); a_assert(ip->putBackTokenId == 0); /* * Create the parse token buffer and script buffer */ if (ringqOpen(&ip->tokbuf, EJ_INC, -1) < 0) { return -1; } if (ringqOpen(&ip->script, EJ_SCRIPT_INC, -1) < 0) { return -1; } /* * Put the Ejscript into a ring queue for easy parsing */ ringqPutStr(&ip->script, script); ip->lineNumber = 1; ip->lineLength = 0; ip->lineColumn = 0; ip->line = NULL; return 0; }