/*------------------------------------------------------------------ * ipcHttpHdrComplete * * This checks if HTTP request headers are completely received, i.e. * if there is an empty line at the end of headers. If so, returns * total length of the headers (in bytes) otherwise returns 0. * * startOffset is necessary because as we read headers piece by piece * we dont want to check them every time from the very beginning. *----------------------------------------------------------------*/ RsslInt32 ipcHttpHdrComplete(char *data, RsslInt32 datalen, RsslInt32 startOffset) { RsslInt32 i = startOffset, eoflen, slen = 0; if (datalen == 0) return 0; while(startOffset > 0 && iseof(data,startOffset,datalen) > 0) startOffset--; i = startOffset; while(i < datalen) { eoflen = iseof(data,i,datalen); if (eoflen == 0) { slen++; i++; continue; } /* we did hit eof, let's see what's here */ if (slen == 0) /* empty line designates end of http headers */ { return i+eoflen; } /* else we just passed yet another line */ i += eoflen; slen = 0; } /* here we are if not yet complete */ return 0; }
size_t MemFile::write(const void *src, size_t bytes) { if(iseof()) return 0; size_t rem = std::min((size_t)(_size - _pos), bytes); memcpy((char*)_buf + _pos, src, rem); return rem; }
size_t MemFile::read(void *dst, size_t bytes) { if(iseof()) return 0; size_t rem = std::min((size_t)(_size - _pos), bytes); memcpy(dst, (char*)_buf + _pos, rem); return rem; }
unsigned int VFSFileMem::write(const void *src, unsigned int bytes) { VFS_GUARD_OPT(this); if(iseof()) return 0; unsigned int rem = std::min<unsigned int>((unsigned int)(_size - _pos), bytes); memcpy((char*)_buf + _pos, src, rem); return rem; }
unsigned int VFSFileMem::read(void *dst, unsigned int bytes) { VFS_GUARD_OPT(this); if(iseof()) return 0; unsigned int rem = std::min<unsigned int>((unsigned int)(_size - _pos), bytes); memcpy(dst, (char*)_buf + _pos, rem); return rem; }
syscall getnum(void) { int i = 0, c = 0; control(CONSOLE, TTY_CTRL_SET_IFLAG, TTY_ECHO, 0); fprintf(CONSOLE, "? "); c = getchar(); while (('\n' != c) && ('\r' != c) && (!iseof(c))) { if (('0' <= c) && ('9' >= c)) { i = i * 10 + c - '0'; } c = getchar(); } if (EOF == c) return c; return i; }