See Also
Quick Nav
Mpr - Portable Runtime Native API
The Multithreaded Portable Runtime (MPR) is a runtime library for embedded applications.
The MPR provides management for logging, error handling, events, files, http, memory, ssl, sockets, strings, xml parsing, and date/time functions. It also provides a foundation of safe routines for secure programming, that help to prevent buffer overflows and other security threats. It is correctly handles null arguments without crashing. The MPR is a library and a C API that can be used in both C and C++ programs.
The MPR uses by convention a set extended typedefs for common types. These include: bool, cchar, cvoid, uchar, short, ushort, int, uint, long, ulong, int64, uint64, float, and double. The cchar type is a const char, cvoid is const void, and several types have "u" prefixes to denote unsigned qualifiers.
The MPR includes a memory manager to minimize memory leaks and maximize allocation efficiency. It utilizes a heap and slab allocators with tree links. All memory allocated is connected to a parent memory block thus forming a tree. When any block is freed, all child blocks are also freed. Most MPR APIs take a memory parent context as the first parameter.
Many of these APIs are not thread-safe. If utilizing multithreaded programming on a supporting operating system, be careful if you modify or delete the underlying data while accessing the resource from another thread.
Components
Mpr | Primary MPR application control structure. |
MprBuf | Dynamic Buffer Module. |
MprCmd | Command execution Service. |
MprDate | Date and Time Service. |
MprFile | File I/O Module. |
MprHash | Hash table entry structure. |
MprLog | Logging Services. |
MprModule | Loadable Module Service. |
MprSocket | Socket Service. |
MprSynch | Multithreaded Synchronization Services. |
MprThread | Thread Service. |
MprWaitHandler | Wait Handler Service. |
MprWorkerService | Worker Thread Service. |
Functions
char* | mprAsprintf(MprCtx ctx, int maxSize, cchar *fmt, ...) |
Format a string into an allocated buffer. | |
int64 | mprAtoi(cchar *str, int radix) |
Convert a string to an integer. | |
MprFile* | mprAttachFd(MprCtx ctx, int fd, cchar *name, int omode) |
Attach to an existing file descriptor. | |
void | mprBreakpoint() |
Trigger a breakpoint. | |
void | mprClearList(MprList *list) |
Clears the list of all items. | |
void | mprCloseCmdFd(MprCmd *cmd, int channel) |
Close the command channel. | |
void | mprCloseSocket(MprSocket *sp, bool graceful) |
Close a socket. | |
void | mprCompactBuf(MprBuf *buf) |
Compact the buffer contents. | |
void | mprConfigureSsl(struct MprSsl *ssl) |
Configure SSL based on the parsed MprSsl configuration. | |
MprHashTable* | mprCopyHash(MprCtx ctx, MprHashTable *table) |
Copy a hash table. | |
int | mprCopyList(MprList *dest, MprList *src) |
Copy a list. | |
int | mprCopyPath(MprCtx ctx, cchar *from, cchar *to, int omode) |
Copy a file. | |
Mpr* | mprCreate(int argc, char **argv, MprAllocNotifier cback) |
Create an instance of the MPR. | |
MprBuf* | mprCreateBuf(MprCtx ctx, int initialSize, int maxSize) |
Create a new buffer. | |
MprCmd* | mprCreateCmd(MprCtx ctx) |
Create a new Command object. | |
MprCond* | mprCreateCond(MprCtx ctx) |
Create a condition lock variable. | |
MprDispatcher* | mprCreateDispatcher(MprCtx ctx) |
Create a new event dispatcher. | |
MprEvent* | mprCreateEvent(MprDispatcher *dispatcher, MprEventProc proc, int period, int priority, void *data, int flags) |
Create a new event. | |
Mpr* | mprCreateEx(int argc, char **argv, MprAllocNotifier cback, void *shell) |
Create an instance of the MPR. | |
MprHashTable* | mprCreateHash(MprCtx ctx, int hashSize) |
Create a hash table. | |
MprHttp* | mprCreateHttp(MprCtx ctx) |
Create a Http connection object. | |
int | mprCreateHttpSecret(MprCtx ctx) |
Create a Http secret. | |
MprKeyValue* | mprCreateKeyPair(MprCtx ctx, cchar *key, cchar *value) |
Create a key / value pair. | |
MprList* | mprCreateList(MprCtx ctx) |
Create a list. | |
MprMutex* | mprCreateLock(MprCtx ctx) |
Create a Mutex lock object. | |
MprModule* | mprCreateModule(MprCtx ctx, cchar *name, cchar *version, void *moduleData, MprModuleProc start, MprModuleProc stop) |
Create a module. | |
MprSocket* | mprCreateSocket(MprCtx ctx, struct MprSsl *ssl) |
Create a socket. | |
MprSpin* | mprCreateSpinLock(MprCtx ctx) |
Create a spin lock lock object. | |
MprThread* | mprCreateThread(MprCtx ctx, cchar *name, MprThreadProc proc, void *data, int priority, int stackSize) |
Create a new thread. | |
MprEvent* | mprCreateTimerEvent(MprDispatcher *dispatcher, MprEventProc proc, int period, int priority, void *data, int flags) |
Create a timer event. | |
MprWaitHandler* | mprCreateWaitHandler(MprCtx ctx, int fd, int mask, MprWaitProc proc, void *data, int priority, int flags) |
Create a wait handler. | |
int | mprDecode64(char *buffer, int bufsize, cchar *str) |
Deocde buffer using base-46 encoding. | |
struct tm* | mprDecodeLocalTime(MprCtx ctx, struct tm *timep, MprTime time) |
Decode a time value into a tokenized local time value. | |
struct tm* | mprDecodeUniversalTime(MprCtx ctx, struct tm *timep, MprTime time) |
Decode a time value into a tokenized UTC time structure. | |
void | mprDedicateWorker(MprWorker *worker) |
Dedicate a worker thread to a current real thread. | |
void | mprDedicateWorkerToHandler(MprWaitHandler *wp, struct MprWorker *worker) |
Dedicate a worker thread to a wait handler. | |
int | mprDeletePath(MprCtx ctx, cchar *path) |
Delete a file. | |
void | mprDisableCmdEvents(MprCmd *cmd, int channel) |
Disable command I/O events. | |
void | mprDisableFileBuffering(MprFile *file) |
Disable file buffering. | |
void | mprDisableSocketEvents(MprSocket *sp) |
Disable socket events for a socket callback. | |
void | mprDisableWaitEvents(MprWaitHandler *wp) |
Disable wait events. | |
void | mprDisconnectCmd(MprCmd *cmd) |
Disconnect a command its underlying I/O channels. | |
void | mprDisconnectHttp(MprHttp *http) |
Disconnect a Http connection. | |
void | mprDisconnectSocket(MprSocket *sp) |
Disconnect a socket by closing its underlying file descriptor. | |
void | mprDisconnectWaitHandler(MprWaitHandler *wp) |
Disconnect a wait handler from its underlying file descriptor. | |
char* | mprDtoa(MprCtx ctx, double value, int ndigits, int mode, int flags) |
Convert a double to ascii. | |
MprList* | mprDupList(MprCtx ctx, MprList *src) |
Duplicate a list. | |
void | mprEnableCmdEvents(MprCmd *cmd, int channel) |
Enable command I/O events. | |
int | mprEnableFileBuffering(MprFile *file, int size, int maxSize) |
Enable file buffering. | |
void | mprEnableHttpUpload(MprHttp *http) |
Enable Multipart-Mime file upload for this request. | |
void | mprEnableSocketEvents(MprSocket *sp) |
Enable socket events for a socket callback. | |
void | mprEnableWaitEvents(MprWaitHandler *wp) |
Enable wait events. | |
void | mprEncode64(char *buffer, int bufsize, cchar *str) |
Encode buffer using base-46 encoding. | |
void | mprError(MprCtx ctx, cchar *fmt, ...) |
Log an error message. | |
char* | mprEscapeCmd(MprCtx ctx, cchar *cmd, int escChar) |
Encode a string escaping typical command (shell) characters. | |
char* | mprEscapeHtml(MprCtx ctx, cchar *html) |
Encode a string by escaping typical HTML characters. | |
void | mprFatalError(MprCtx ctx, cchar *fmt, ...) |
Log a fatal error message and exit. | |
int | mprFinalizeHttpWriting(MprHttp *http) |
Finalize writing Http data. | |
int | mprFlush(MprFile *file) |
Flush any buffered write data. | |
void | mprFlushBuf(MprBuf *buf) |
Flush the buffer contents. | |
int | mprFlushSocket(MprSocket *sp) |
Flush a socket. | |
char* | mprFormatLocalTime(MprCtx ctx, MprTime time) |
Convert a time value to local time and format as a string. | |
char* | mprFormatTime(MprCtx ctx, cchar *fmt, struct tm *timep) |
Format a time value as a local time. | |
char* | mprFormatUri(MprCtx ctx, cchar *protocol, cchar *host, int port, cchar *path, cchar *query) |
Format a URI. | |
int | mprFprintf(struct MprFile *file, cchar *fmt, ...) |
Print a formatted message to a file descriptor. | |
int | mprFree(void *ptr) |
Free a block of memory. | |
void | mprFreeChildren(MprCtx ctx) |
Free all the children blocks allocated of a block. | |
char* | mprGetAbsPath(MprCtx ctx, cchar *path) |
Convert a path to an absolute path. | |
MprAlloc* | mprGetAllocStats(MprCtx ctx) |
Return the current allocation memory statistics block. | |
cchar* | mprGetAppName(MprCtx ctx) |
Get the application name defined via mprSetAppName. | |
int | mprGetAvailableWorkers(MprCtx ctx) |
Get the count of available worker threads Return the count of free threads in the worker thread pool. | |
int | mprGetBlockFromBuf(MprBuf *buf, char *blk, int count) |
Get a block of data from the buffer. | |
char* | mprGetBufEnd(MprBuf *buf) |
Get a reference to the end of the buffer contents. | |
int | mprGetBufLength(MprBuf *buf) |
Get the buffer content length. | |
char* | mprGetBufOrigin(MprBuf *buf) |
Get the origin of the buffer content storage. | |
MprBufProc | mprGetBufRefillProc(MprBuf *buf) |
Get the buffer refill procedure. | |
int | mprGetBufSize(MprBuf *buf) |
Get the current size of the buffer content storage. | |
int | mprGetBufSpace(MprBuf *buf) |
Get the space available to store content. | |
char* | mprGetBufStart(MprBuf *buf) |
Get the start of the buffer contents. | |
int | mprGetc(MprFile *file) |
Read a character from the file. | |
int | mprGetCharFromBuf(MprBuf *buf) |
Get a character from the buffer. | |
MprBuf* | mprGetCmdBuf(MprCmd *cmd, int channel) |
Get the underlying buffer for a channel. | |
int | mprGetCmdExitStatus(MprCmd *cmd, int *status) |
Get the command exit status. | |
int | mprGetCmdFd(MprCmd *cmd, int channel) |
Get the underlying file descriptor for an I/O channel. | |
MprOsThread | mprGetCurrentOsThread() |
Get the O/S thread. | |
char* | mprGetCurrentPath(MprCtx ctx) |
Return the current working directory. | |
MprThread* | mprGetCurrentThread(MprCtx ctx) |
Get the currently executing thread. | |
bool | mprGetDebugMode(MprCtx ctx) |
Get the debug mode. | |
MprTime | mprGetElapsedTime(MprCtx ctx, MprTime mark) |
Get the elapsed time since a time mark. | |
int | mprGetError() |
Return the error code for the most recent system or library operation. | |
MprOffset | mprGetFilePosition(MprFile *file) |
Return the current file position. | |
MprOffset | mprGetFileSize(MprFile *file) |
Get the size of the file. | |
MprHash* | mprGetFirstHash(MprHashTable *table) |
Return the first symbol in a symbol entry. | |
void* | mprGetFirstItem(MprList *list) |
Get the first item in the list. | |
int | mprGetHashCount(MprHashTable *table) |
Return the count of symbols in a symbol entry. | |
int | mprGetHttpChunked(MprHttp *http) |
Return whether transfer chunked encoding will be used on this request. | |
int | mprGetHttpCode(MprHttp *http) |
Get the Http response code. | |
cchar* | mprGetHttpCodeString(MprCtx ctx, int code) |
Get the Http reponse code as a string. | |
int | mprGetHttpContentLength(MprHttp *http) |
Get the response content length. | |
cchar* | mprGetHttpDefaultHost(MprHttp *http) |
Get the default host. | |
int | mprGetHttpDefaultPort(MprHttp *http) |
Get the default port. | |
cchar* | mprGetHttpError(MprHttp *http) |
Get the Http error message. | |
int | mprGetHttpFlags(MprHttp *http) |
Return the http flags. | |
cchar* | mprGetHttpHeader(MprHttp *http, cchar *key) |
Get a http response header. | |
char* | mprGetHttpHeaders(MprHttp *http) |
Get all the http response headers. | |
MprHashTable* | mprGetHttpHeadersHash(MprHttp *http) |
Get the hash table of response Http headers. | |
cchar* | mprGetHttpMessage(MprHttp *http) |
Get the Http response message. | |
int | mprGetHttpState(MprHttp *http) |
Get the http state. | |
void* | mprGetItem(MprList *list, int index) |
Get an list item. | |
void* | mprGetLastItem(MprList *list) |
Get the last item in the list. | |
int | mprGetListCapacity(MprList *list) |
Get the current capacity of the list. | |
int | mprGetListCount(MprList *list) |
Get the number of items in the list. | |
MprLogHandler | mprGetLogHandler(MprCtx ctx) |
Get the current MPR debug log handler. | |
int | mprGetMaxWorkers(MprCtx ctx) |
Get the maximum count of worker pool threads Get the maximum limit of worker pool threads. | |
cchar* | mprGetModuleSearchPath(MprCtx ctx) |
Get the module search path. | |
char* | mprGetNativePath(MprCtx ctx, cchar *path) |
Get a path formatted according to the native O/S conventions. | |
MprHash* | mprGetNextHash(MprHashTable *table, MprHash *last) |
Return the next symbol in a symbol entry. | |
void* | mprGetNextItem(MprList *list, int *lastIndex) |
Get the next item in the list. | |
char* | mprGetNormalizedPath(MprCtx ctx, cchar *path) |
Normalize a path. | |
int | mprGetOsError() |
Return the O/S error code. | |
int | mprGetPageSize(MprCtx ctx) |
Get the current O/S virtual page size. | |
void* | mprGetParent(MprCtx ctx) |
Get the memory parent of a block. | |
char* | mprGetPathBase(MprCtx ctx, cchar *path) |
Get the base portion of a path. | |
char* | mprGetPathDir(MprCtx ctx, cchar *path) |
Get the directory portion of a path. | |
cchar* | mprGetPathExtension(MprCtx ctx, cchar *path) |
Get the file extension portion of a path. | |
MprList* | mprGetPathFiles(MprCtx ctx, cchar *dir, bool enumDirs) |
Create a directory list of files. | |
int | mprGetPathInfo(MprCtx ctx, cchar *path, MprPath *info) |
Return information about a file represented by a path. | |
char* | mprGetPathLink(MprCtx ctx, cchar *path) |
Get the target of a symbolic link. | |
cchar* | mprGetPathNewline(MprCtx ctx, cchar *path) |
Get the file newline character string for a given path. | |
char* | mprGetPathParent(MprCtx ctx, cchar *path) |
Get the parent directory of a path. | |
cchar* | mprGetPathSeparators(MprCtx ctx, cchar *path) |
Get the path directory separator. | |
char* | mprGetPortablePath(MprCtx ctx, cchar *path) |
Get a portable path. | |
void* | mprGetPrevItem(MprList *list, int *lastIndex) |
Get the previous item in the list. | |
char* | mprGetRelPath(MprCtx ctx, cchar *path) |
Get a relative path. | |
MprTime | mprGetRemainingTime(MprCtx ctx, MprTime mark, uint timeout) |
Return the time remaining until a timeout has elapsed. | |
char* | mprGets(MprFile *file, char *buf, uint size) |
Read a line from the file. | |
bool | mprGetSocketBlockingMode(MprSocket *sp) |
Get the socket blocking mode. | |
int | mprGetSocketError(MprSocket *sp) |
Get a socket error code. | |
int | mprGetSocketFd(MprSocket *sp) |
Get the socket file descriptor. | |
int | mprGetSocketPort(MprSocket *sp) |
Get the port used by a socket. | |
MprFile* | mprGetStderr(MprCtx ctx) |
Return a file object for the Stderr I/O channel. | |
MprFile* | mprGetStdin(MprCtx ctx) |
Return a file object for the Stdin I/O channel. | |
MprFile* | mprGetStdout(MprCtx ctx) |
Return a file object for the Stdout I/O channel. | |
char* | mprGetTempPath(MprCtx ctx, cchar *tmpDir) |
Make a temporary file. | |
cchar* | mprGetThreadName(MprThread *thread) |
Get the thread name. | |
int | mprGetThreadPriority(MprThread *thread) |
Get the thread priroity. | |
MprTime | mprGetTime(MprCtx ctx) |
Get the system time. | |
char* | mprGetTransformedPath(MprCtx ctx, cchar *path, int flags) |
Transform a path. | |
int64 | mprGetUsedMemory(MprCtx ctx) |
Return the amount of memory currently used by the application. | |
char* | mprGetWordTok(char *buf, int bufsize, cchar *str, cchar *delim, cchar **tok) |
Get the next word token. | |
void | mprGlobalLock(MprCtx ctx) |
Globally lock the application. | |
void | mprGlobalUnlock(MprCtx ctx) |
Unlock the global mutex. | |
int | mprGrowBuf(MprBuf *buf, int count) |
Grow the buffer. | |
bool | mprHasAllocError(MprCtx ctx) |
Determine if the MPR has encountered memory allocation errors. | |
bool | mprHasSocketPendingData(MprSocket *sp) |
Test if the socket has buffered read data. | |
int | mprHttpRequest(MprHttp *http, cchar *method, cchar *uri) |
Issue a new Http request and wait for completion. | |
void | mprInitList(MprList *list) |
Initialize a list structure. | |
MprMutex* | mprInitLock(MprCtx ctx, MprMutex *mutex) |
Initialize a statically allocated Mutex lock object. | |
MprSpin* | mprInitSpinLock(MprCtx ctx, MprSpin *lock) |
Initialize a statically allocated spinlock object. | |
int | mprInsertCharToBuf(MprBuf *buf, int c) |
Insert a character into the buffer. | |
int | mprInsertItemAtPos(MprList *list, int index, cvoid *item) |
Insert an item into a list at a specific position. | |
void | mprInvokeWaitCallback(MprWaitHandler *wp) |
Invoke the wait handler callback. | |
bool | mprIsAbsPath(MprCtx ctx, cchar *path) |
Determine if a path is absolute. | |
bool | mprIsCmdRunning(MprCmd *cmd) |
Test if the command is still running. | |
bool | mprIsExiting(MprCtx ctx) |
Determine if the MPR should exit. | |
bool | mprIsHttpComplete(MprHttp *http) |
Test if the Http request is complete. | |
bool | mprIsRelPath(MprCtx ctx, cchar *path) |
Determine if a path is relative. | |
bool | mprIsSocketEof(MprSocket *sp) |
Test if the other end of the socket has been closed. | |
bool | mprIsSocketSecure(MprSocket *sp) |
Determine if the socket is secure. | |
int | mprIsValid(MprCtx ctx) |
Test is a pointer is a valid memory context. | |
char* | mprItoa(char *buf, int size, int64 value, int radix) |
Convert an integer to a string. | |
char* | mprJoinPath(MprCtx ctx, cchar *dir, cchar *other) |
Join paths. | |
char* | mprJoinPathExt(MprCtx ctx, cchar *dir, cchar *ext) |
Join an extension to a path. | |
MprModule* | mprLoadModule(MprCtx ctx, cchar *filename, cchar *entryPoint) |
Load a module. | |
MprModule* | mprLoadSsl(MprCtx ctx, bool lazy) |
Load the SSL module. | |
void | mprLock(MprMutex *lock) |
Lock access. | |
void | mprLog(MprCtx ctx, int level, cchar *fmt, ...) |
Write a message to the diagnostic log file. | |
int | mprLookAtLastCharInBuf(MprBuf *buf) |
Peek at the last character in the buffer. | |
int | mprLookAtNextCharInBuf(MprBuf *buf) |
Peek at the next character in the buffer. | |
cvoid* | mprLookupHash(MprHashTable *table, cchar *key) |
Lookup a symbol in the hash table. | |
MprHash* | mprLookupHashEntry(MprHashTable *table, cchar *key) |
Lookup a symbol in the hash table and return the hash entry. | |
int | mprLookupItem(MprList *list, cvoid *item) |
Find an item and return its index. | |
cchar* | mprLookupMimeType(MprCtx ctx, cchar *ext) |
Get the mime type for an extension. | |
MprModule* | mprLookupModule(MprCtx ctx, cchar *name) |
Lookup a module. | |
int | mprMakeCmdIO(MprCmd *cmd) |
Make the I/O channels to send and receive data to and from the command. | |
int | mprMakeDir(MprCtx ctx, cchar *path, int perms, bool makeMissing) |
Make a directory. | |
int | mprMakeLink(MprCtx ctx, cchar *path, cchar *target, bool hard) |
Make a link. | |
void* | mprMapAlloc(uint size, int mode) |
Memory virtual memory into the applications address space. | |
void | mprMapFree(void *ptr, uint size) |
Free (unpin) a mapped section of virtual memory. | |
void | mprMapSeparators(MprCtx ctx, char *path, int separator) |
Map the separators in a path. | |
int | mprMemcmp(cvoid *b1, int b1Len, cvoid *b2, int b2Len) |
Compare two byte strings. | |
int | mprMemcpy(void *dest, int destMax, cvoid *src, int nbytes) |
Safe copy for a block of data. | |
void | mprMemoryError(MprCtx ctx, cchar *fmt, ...) |
Log a memory error message. | |
bool | mprNeedHttpRetry(MprHttp *http, char **url) |
Test if the request needs a transparent retry to implement authentication or redirection. | |
MprFile* | mprOpen(MprCtx ctx, cchar *filename, int omode, int perms) |
Open a file. | |
int | mprOpenClientSocket(MprSocket *sp, cchar *hostName, int port, int flags) |
Open a client socket. | |
int | mprOpenServerSocket(MprSocket *sp, cchar *ipAddr, int port, MprSocketAcceptProc acceptFn, void *data, int flags) |
Open a server socket. | |
int | mprParseIp(MprCtx ctx, cchar *ipSpec, char **ipAddr, int *port, int defaultPort) |
Parse an IP address. | |
MprUri* | mprParseUri(MprCtx ctx, cchar *uri) |
Parse a URI. | |
bool | mprPathExists(MprCtx ctx, cchar *path, int omode) |
Determine if a file exists for a path name and can be accessed. | |
int | mprPeekc(MprFile *file) |
Non-destructively read a character from the file. | |
void | mprPollCmdPipes(MprCmd *cmd, int timeout) |
Poll for I/O on the command pipes. | |
int | mprPrintf(MprCtx ctx, cchar *fmt, ...) |
Formatted print. | |
int | mprPrintfError(MprCtx ctx, cchar *fmt, ...) |
Print a formatted message to the standard error channel. | |
int | mprPutBlockToBuf(MprBuf *buf, cchar *ptr, int size) |
Put a block to the buffer. | |
int | mprPutc(MprFile *file, int c) |
Write a character to the file. | |
int | mprPutCharToBuf(MprBuf *buf, int c) |
Put a character to the buffer. | |
int | mprPutFmtToBuf(MprBuf *buf, cchar *fmt, ...) |
Put a formatted string to the buffer. | |
int | mprPutIntToBuf(MprBuf *buf, int i) |
Put an integer to the buffer. | |
int | mprPuts(MprFile *file, cchar *str) |
Write a string to the file. | |
int | mprPutStringToBuf(MprBuf *buf, cchar *str) |
Put a string to the buffer. | |
void | mprRawLog(MprCtx ctx, int level, cchar *fmt, ...) |
Write a raw log message to the diagnostic log file. | |
int | mprRead(MprFile *file, void *buf, uint size) |
Read data from a file. | |
int | mprReadCmdPipe(MprCmd *cmd, int channel, char *buf, int bufsize) |
Make the I/O channels to send and receive data to and from the command. | |
int | mprReadHttp(MprHttp *http, char *buffer, int size) |
Read Http response data. | |
char* | mprReadHttpString(MprHttp *http) |
Read response data as a string. | |
int | mprReadSocket(MprSocket *sp, void *buf, int size) |
Read from a socket. | |
void* | mprRealloc(MprCtx ctx, void *ptr, uint size) |
Reallocate a block. | |
char* | mprReallocStrcat(MprCtx ctx, int max, char *buf, cchar *src, ...) |
Append strings to an existing string and reallocate as required. | |
int | mprReapCmd(MprCmd *cmd, int timeout) |
Reap the command. | |
void | mprRecallWaitHandler(MprWaitHandler *wp) |
Recall a wait handler. | |
int | mprRefillBuf(MprBuf *buf) |
Refill the buffer with data. | |
void | mprReleaseWorker(MprWorker *worker) |
Release a worker thread. | |
void | mprReleaseWorkerFromHandler(MprWaitHandler *wp, struct MprWorker *worker) |
Release a worker thread. | |
void | mprRemoveEvent(MprEvent *event) |
Remove an event. | |
int | mprRemoveHash(MprHashTable *table, cchar *key) |
Remove a symbol entry from the hash table. | |
int | mprRemoveItem(MprList *list, void *item) |
Remove an item from the list. | |
int | mprRemoveItemAtPos(MprList *list, int index) |
Remove an item from the list. | |
int | mprRemoveLastItem(MprList *list) |
Remove the last item from the list. | |
int | mprRemoveRangeOfItems(MprList *list, int start, int end) |
Remove a range of items from the list. | |
void | mprRescheduleEvent(MprEvent *event, int period) |
Reschedule an event. | |
void | mprResetAllocError(MprCtx ctx) |
Reset the memory allocation error flag. | |
void | mprResetBufIfEmpty(MprBuf *buf) |
Reset the buffer. | |
void | mprResetCond(MprCond *cond) |
Reset a condition variable. | |
void | mprResetHttpCredentials(MprHttp *http) |
Reset Http credentials. | |
void | mprRestartContinuousEvent(MprEvent *event) |
Restart an event. | |
int | mprRunCmd(MprCmd *cmd, cchar *command, char **out, char **err, int flags) |
Run a command using a string command line. | |
int | mprRunCmdV(MprCmd *cmd, int argc, char **argv, char **out, char **err, int flags) |
Run a command using an argv[] array of arguments. | |
int | mprSamePath(MprCtx ctx, cchar *path1, cchar *path2) |
Compare two paths if they are the same. | |
int | mprSamePathCount(MprCtx ctx, cchar *path1, cchar *path2, int len) |
Compare two paths if they are the same for a given length. | |
int | mprSearchForModule(MprCtx ctx, cchar *module, char **path) |
Search for a module on the current module path. | |
char* | mprSearchPath(MprCtx ctx, cchar *path, int flags, cchar *search, ...) |
Search for a path. | |
long | mprSeek(MprFile *file, int seekType, long distance) |
Seek the I/O pointer to a new location in the file. | |
int | mprServiceEvents(MprDispatcher *dispatcher, int delay, int flags) |
Service events. | |
void | mprSetAllocError(MprCtx ctx) |
Set an memory allocation error condition on a memory context. | |
void | mprSetAllocLimits(MprCtx ctx, int redline, int maxMemory) |
Configure the application memory limits. | |
int | mprSetAppName(MprCtx ctx, cchar *name, cchar *title, cchar *version) |
Set the application name, title and version. | |
void | mprSetBufMax(MprBuf *buf, int maxSize) |
Set the maximum buffer size. | |
void | mprSetBufRefillProc(MprBuf *buf, MprBufProc fn, void *arg) |
Set the buffer refill procedure. | |
int | mprSetBufSize(MprBuf *buf, int size, int maxSize) |
Set the buffer size. | |
void | mprSetCmdCallback(MprCmd *cmd, MprCmdProc callback, void *data) |
Define a callback to be invoked to receive response data from the command. | |
void | mprSetCmdDir(MprCmd *cmd, cchar *dir) |
Set the home directory for the command. | |
void | mprSetCmdEnv(MprCmd *cmd, cchar **env) |
Set the command environment. | |
void | mprSetCurrentThreadPriority(MprCtx ctx, int priority) |
Set the thread priroity for the current thread. | |
void | mprSetDebugMode(MprCtx ctx, bool on) |
Turn on debug mode. | |
void | mprSetDestructor(void *ptr, MprDestructor destructor) |
Update the destructor for a block of memory. | |
int | mprSetFormattedHttpHeader(MprHttp *http, bool overwrite, cchar *key, cchar *fmt, ...) |
Add a request header using a format string. | |
int | mprSetHttpBody(MprHttp *http, cchar *body, int len) |
Set the http request body content. | |
void | mprSetHttpBufferSize(MprHttp *http, int initialSize, int maxSize) |
Set the Http buffer size. | |
void | mprSetHttpCallback(MprHttp *http, MprHttpProc fn, void *arg, int mask) |
Define a Http callback. | |
int | mprSetHttpChunked(MprHttp *http, int enable) |
Set whether transfer chunked encoding will be used on this request. | |
void | mprSetHttpContentLength(MprHttp *http, int length) |
Define a request content length. | |
void | mprSetHttpCredentials(MprHttp *http, cchar *username, cchar *password) |
Set the Http credentials. | |
void | mprSetHttpDefaultHost(MprHttp *http, cchar *host) |
Define a default host. | |
void | mprSetHttpDefaultPort(MprHttp *http, int port) |
Define a default port. | |
void | mprSetHttpFollowRedirects(MprHttp *http, bool follow) |
Follow redirctions. | |
int | mprSetHttpHeader(MprHttp *http, bool overwrite, cchar *key, cchar *value) |
Add a request header. | |
void | mprSetHttpKeepAlive(MprHttp *http, bool on) |
Control Http Keep-Alive. | |
void | mprSetHttpProtocol(MprHttp *http, cchar *protocol) |
Set the Http protocol variant. | |
void | mprSetHttpProxy(MprHttp *http, cchar *host, int port) |
Define a Http proxy host. | |
void | mprSetHttpRetries(MprHttp *http, int retries) |
Set the Http retry count. | |
int | mprSetHttpTimeout(MprHttp *http, int timeout) |
Set the Http inactivity timeout. | |
void* | mprSetItem(MprList *list, int index, cvoid *item) |
Set a list item. | |
int | mprSetListLimits(MprList *list, int initialSize, int maxSize) |
Define the list size limits. | |
void | mprSetLogHandler(MprCtx ctx, MprLogHandler handler, void *handlerData) |
Set an MPR debug log handler. | |
void | mprSetLogLevel(MprCtx ctx, int level) |
Set the current logging level. | |
int | mprSetMaxSocketClients(MprCtx ctx, int max) |
Set the maximum number of client sockets that are permissable. | |
void | mprSetMaxWorkers(MprCtx ctx, int count) |
Set the maximum count of worker threads Set the maximum number of worker pool threads for the MPR. | |
void | mprSetMinWorkers(MprCtx ctx, int count) |
Set the minimum count of worker threads Set the count of threads the worker pool will have. | |
void | mprSetModuleSearchPath(MprCtx ctx, char *searchPath) |
Set the module search path. | |
int | mprSetSocketBlockingMode(MprSocket *sp, bool on) |
Set the socket blocking mode. | |
void | mprSetSocketCallback(MprSocket *sp, MprSocketProc fn, void *data, int mask, int priority) |
Set the socket callback. | |
void | mprSetSocketEof(MprSocket *sp, bool eof) |
Set an EOF condition on the socket. | |
void | mprSetSocketEventMask(MprSocket *sp, int mask) |
Define the events of interest for a socket. | |
int | mprSetSocketNoDelay(MprSocket *sp, bool on) |
Set the socket delay mode. | |
void | mprSetThreadPriority(MprThread *thread, int priority) |
Set the thread priroity. | |
void | mprSetWaitCallback(MprWaitHandler *wp, MprWaitProc proc, int mask) |
Define the wait handler callback. | |
void | mprSetWaitEvents(MprWaitHandler *wp, int desiredMask, int disableMask) |
Define the events of interest for a wait handler. | |
void | mprSetWorkerStackSize(MprCtx ctx, int size) |
Set the default worker stack size. | |
void | mprSignalCond(MprCond *cond) |
Signal a condition lock variable. | |
void | mprSignalExit(MprCtx ctx) |
Signal the MPR to exit gracefully. | |
void | mprSortList(MprList *list, MprListCompareProc compare) |
Sort a list. | |
void | mprSpinLock(MprSpin *lock) |
Lock a spinlock. | |
void | mprSpinUnlock(MprSpin *lock) |
Unlock a spinlock. | |
char* | mprSprintf(char *buf, int maxSize, cchar *fmt, ...) |
Format a string into a statically allocated buffer. | |
bool | mprStackCheck(MprCtx ctx) |
Monitory stack usage and check if the stack has grown since last monitoring. | |
int | mprStart(Mpr *mpr, int startEventsThread) |
Start the Mpr services. | |
int | mprStartCmd(MprCmd *cmd, int argc, char **argv, char **envp, int flags) |
Start the command. | |
int | mprStartHttpRequest(MprHttp *http, cchar *method, cchar *uri) |
Start a new Http request. | |
int | mprStartThread(MprThread *thread) |
Start a thread. | |
void | mprStaticAssert(cchar *loc, cchar *msg) |
Output an assertion failed message. | |
void | mprStaticError(MprCtx ctx, cchar *fmt, ...) |
Write a message to the diagnostic log file without allocating any memory. | |
int | mprStaticPrintf(MprCtx ctx, cchar *fmt, ...) |
Print a message to the applications standard output without allocating memory. | |
int | mprStaticPrintfError(MprCtx ctx, cchar *fmt, ...) |
Print a message to the standard error channel without allocating memory. | |
int | mprStealBlock(MprCtx ctx, cvoid *ptr) |
Reassign a block from its current parent context to a new context. | |
char* | mprStealBuf(MprCtx ctx, MprBuf *buf) |
Steal the buffer memory from a buffer. | |
void | mprStop(Mpr *mpr) |
Stop the MPR and shutdown all services. | |
void | mprStopCmd(MprCmd *cmd) |
Stop the command. | |
void | mprStopContinuousEvent(MprEvent *event) |
Stop an event. | |
char* | mprStrcat(MprCtx ctx, int max, cchar *src, ...) |
Catenate strings. | |
int | mprStrcmp(cchar *str1, cchar *str2) |
Compare strings. | |
int | mprStrcmpAnyCase(cchar *str1, cchar *str2) |
Compare strings ignoring case. | |
int | mprStrcmpAnyCaseCount(cchar *str1, cchar *str2, int len) |
Compare strings ignoring case. | |
int | mprStrcpy(char *dest, int destMax, cchar *src) |
Copy a string. | |
int | mprStrcpyCount(char *dest, int destMax, cchar *src, int count) |
Copy characters from a string. | |
char* | mprStrdup(MprCtx ctx, cchar *str) |
Safe replacement for strdup. | |
int | mprStrlen(cchar *src, int max) |
Return the length of a string. | |
char* | mprStrLower(char *str) |
Convert a string to lower case. | |
char* | mprStrndup(MprCtx ctx, cchar *str, uint size) |
Duplicate a string. | |
char* | mprStrnstr(cchar *str, cchar *pattern, int len) |
Find a substring. | |
char* | mprStrTok(char *str, cchar *delim, char **last) |
Tokenize a string. | |
char* | mprStrTrim(char *str, cchar *set) |
Trim a string. | |
char* | mprStrUpper(char *str) |
Convert a string to upper case. | |
void | mprTerminate(MprCtx ctx, bool graceful) |
Terminate the MPR. | |
char* | mprTrimPathExtension(MprCtx ctx, cchar *path) |
Trim an extension from a path. | |
int | mprTruncatePath(MprCtx ctx, cchar *path, int size) |
Truncate a path. | |
bool | mprTryLock(MprMutex *lock) |
Attempt to lock access. | |
bool | mprTrySpinLock(MprSpin *lock) |
Attempt to lock access on a spin lock. | |
void | mprUnloadModule(MprModule *mp) |
Unload a module. | |
void | mprUnlock(MprMutex *lock) |
Unlock a mutex. | |
void | mprUpdateWaitHandler(MprWaitHandler *wp, bool wakeup) |
Apply wait handler updates. | |
char* | mprUrlDecode(MprCtx ctx, cchar *url) |
Decode a URL string by de-scaping URL characters. | |
char* | mprUrlEncode(MprCtx ctx, cchar *url) |
Encode a string by escaping URL characters. | |
void | mprUserError(MprCtx ctx, cchar *fmt, ...) |
Display an error message to the user. | |
char* | mprValidateUrl(MprCtx ctx, char *url) |
Validate a URL. | |
char* | mprVasprintf(MprCtx ctx, int maxSize, cchar *fmt, va_list arg) |
Allocate a buffer of sufficient length to hold the formatted string. | |
char* | mprVsprintf(char *buf, int maxSize, cchar *fmt, va_list args) |
Format a string into a statically allocated buffer. | |
int | mprWaitForCmd(MprCmd *cmd, int timeout) |
Wait for the command to complete. | |
int | mprWaitForCond(MprCond *cond, int timeout) |
Wait for a condition lock variable. | |
int | mprWaitForCondWithService(MprCond *cond, int timeout) |
Wait for a condition lock variable and pump events while waiting. | |
int | mprWaitForHttp(MprHttp *http, int state, int timeout) |
Wait for http response data to drive the Http request/response to the requested state. | |
int | mprWaitForHttpResponse(MprHttp *http, int timeout) |
Wait for a http response to the request. | |
int | mprWrite(MprFile *file, cvoid *buf, uint count) |
Write data to a file. | |
int | mprWriteCmdPipe(MprCmd *cmd, int channel, char *buf, int bufsize) |
Write data to an I/O channel. | |
int | mprWriteFormat(MprFile *file, cchar *fmt, ...) |
Write formatted data to a file. | |
int | mprWriteHttp(MprHttp *http, cchar *buf, int len) |
Write Http request body data. | |
int | mprWriteHttpUploadData(MprHttp *http, MprList *formData, MprList *fileData) |
Write Http upload body data. | |
int | mprWriteSocket(MprSocket *sp, void *buf, int len) |
Write to a socket. | |
int | mprWriteSocketString(MprSocket *sp, cchar *str) |
Write to a string to a socket. | |
int | mprWriteSocketVector(MprSocket *sp, MprIOVec *iovec, int count) |
Write a vector to a socket. | |
int | mprWriteString(MprFile *file, cchar *str) |
Write a string to a file. | |
void | mprBreakpoint() |
Trigger a breakpoint. | |
Mpr* | mprCreate(int argc, char **argv, MprAllocNotifier cback) |
Create an instance of the MPR. | |
Mpr* | mprCreateEx(int argc, char **argv, MprAllocNotifier cback, void *shell) |
Create an instance of the MPR. | |
bool | mprGetDebugMode(MprCtx ctx) |
Get the debug mode. | |
int | mprGetError() |
Return the error code for the most recent system or library operation. | |
int | mprGetOsError() |
Return the O/S error code. | |
bool | mprIsExiting(MprCtx ctx) |
Determine if the MPR should exit. | |
void | mprSignalExit(MprCtx ctx) |
Signal the MPR to exit gracefully. | |
void | mprTerminate(MprCtx ctx, bool graceful) |
Terminate the MPR. | |
void | mprAddNullToBuf(MprBuf *buf) |
Add a null character to the buffer contents. | |
void | mprAdjustBufEnd(MprBuf *buf, int count) |
Adjust the buffer end position. | |
void | mprAdjustBufStart(MprBuf *buf, int count) |
Adjust the buffer start position. | |
void | mprCompactBuf(MprBuf *buf) |
Compact the buffer contents. | |
MprBuf* | mprCreateBuf(MprCtx ctx, int initialSize, int maxSize) |
Create a new buffer. | |
void | mprFlushBuf(MprBuf *buf) |
Flush the buffer contents. | |
int | mprGetBlockFromBuf(MprBuf *buf, char *blk, int count) |
Get a block of data from the buffer. | |
char* | mprGetBufEnd(MprBuf *buf) |
Get a reference to the end of the buffer contents. | |
int | mprGetBufLength(MprBuf *buf) |
Get the buffer content length. | |
char* | mprGetBufOrigin(MprBuf *buf) |
Get the origin of the buffer content storage. | |
MprBufProc | mprGetBufRefillProc(MprBuf *buf) |
Get the buffer refill procedure. | |
int | mprGetBufSize(MprBuf *buf) |
Get the current size of the buffer content storage. | |
int | mprGetBufSpace(MprBuf *buf) |
Get the space available to store content. | |
char* | mprGetBufStart(MprBuf *buf) |
Get the start of the buffer contents. | |
int | mprGetCharFromBuf(MprBuf *buf) |
Get a character from the buffer. | |
int | mprGrowBuf(MprBuf *buf, int count) |
Grow the buffer. | |
int | mprInsertCharToBuf(MprBuf *buf, int c) |
Insert a character into the buffer. | |
int | mprLookAtLastCharInBuf(MprBuf *buf) |
Peek at the last character in the buffer. | |
int | mprLookAtNextCharInBuf(MprBuf *buf) |
Peek at the next character in the buffer. | |
int | mprPutBlockToBuf(MprBuf *buf, cchar *ptr, int size) |
Put a block to the buffer. | |
int | mprPutCharToBuf(MprBuf *buf, int c) |
Put a character to the buffer. | |
int | mprPutFmtToBuf(MprBuf *buf, cchar *fmt, ...) |
Put a formatted string to the buffer. | |
int | mprPutIntToBuf(MprBuf *buf, int i) |
Put an integer to the buffer. | |
int | mprPutStringToBuf(MprBuf *buf, cchar *str) |
Put a string to the buffer. | |
int | mprRefillBuf(MprBuf *buf) |
Refill the buffer with data. | |
void | mprResetBufIfEmpty(MprBuf *buf) |
Reset the buffer. | |
void | mprSetBufMax(MprBuf *buf, int maxSize) |
Set the maximum buffer size. | |
void | mprSetBufRefillProc(MprBuf *buf, MprBufProc fn, void *arg) |
Set the buffer refill procedure. | |
int | mprSetBufSize(MprBuf *buf, int size, int maxSize) |
Set the buffer size. | |
char* | mprStealBuf(MprCtx ctx, MprBuf *buf) |
Steal the buffer memory from a buffer. | |
void | mprCloseCmdFd(MprCmd *cmd, int channel) |
Close the command channel. | |
MprCmd* | mprCreateCmd(MprCtx ctx) |
Create a new Command object. | |
void | mprDisableCmdEvents(MprCmd *cmd, int channel) |
Disable command I/O events. | |
void | mprDisconnectCmd(MprCmd *cmd) |
Disconnect a command its underlying I/O channels. | |
void | mprEnableCmdEvents(MprCmd *cmd, int channel) |
Enable command I/O events. | |
MprBuf* | mprGetCmdBuf(MprCmd *cmd, int channel) |
Get the underlying buffer for a channel. | |
int | mprGetCmdExitStatus(MprCmd *cmd, int *status) |
Get the command exit status. | |
int | mprGetCmdFd(MprCmd *cmd, int channel) |
Get the underlying file descriptor for an I/O channel. | |
bool | mprIsCmdRunning(MprCmd *cmd) |
Test if the command is still running. | |
int | mprMakeCmdIO(MprCmd *cmd) |
Make the I/O channels to send and receive data to and from the command. | |
void | mprPollCmdPipes(MprCmd *cmd, int timeout) |
Poll for I/O on the command pipes. | |
int | mprReadCmdPipe(MprCmd *cmd, int channel, char *buf, int bufsize) |
Make the I/O channels to send and receive data to and from the command. | |
int | mprReapCmd(MprCmd *cmd, int timeout) |
Reap the command. | |
int | mprRunCmd(MprCmd *cmd, cchar *command, char **out, char **err, int flags) |
Run a command using a string command line. | |
int | mprRunCmdV(MprCmd *cmd, int argc, char **argv, char **out, char **err, int flags) |
Run a command using an argv[] array of arguments. | |
void | mprSetCmdCallback(MprCmd *cmd, MprCmdProc callback, void *data) |
Define a callback to be invoked to receive response data from the command. | |
void | mprSetCmdDir(MprCmd *cmd, cchar *dir) |
Set the home directory for the command. | |
void | mprSetCmdEnv(MprCmd *cmd, cchar **env) |
Set the command environment. | |
int | mprStartCmd(MprCmd *cmd, int argc, char **argv, char **envp, int flags) |
Start the command. | |
void | mprStopCmd(MprCmd *cmd) |
Stop the command. | |
int | mprWaitForCmd(MprCmd *cmd, int timeout) |
Wait for the command to complete. | |
int | mprWriteCmdPipe(MprCmd *cmd, int channel, char *buf, int bufsize) |
Write data to an I/O channel. | |
struct tm* | mprDecodeLocalTime(MprCtx ctx, struct tm *timep, MprTime time) |
Decode a time value into a tokenized local time value. | |
struct tm* | mprDecodeUniversalTime(MprCtx ctx, struct tm *timep, MprTime time) |
Decode a time value into a tokenized UTC time structure. | |
char* | mprFormatLocalTime(MprCtx ctx, MprTime time) |
Convert a time value to local time and format as a string. | |
char* | mprFormatTime(MprCtx ctx, cchar *fmt, struct tm *timep) |
Format a time value as a local time. | |
MprTime | mprGetRemainingTime(MprCtx ctx, MprTime mark, uint timeout) |
Return the time remaining until a timeout has elapsed. | |
MprTime | mprGetTime(MprCtx ctx) |
Get the system time. | |
MprFile* | mprAttachFd(MprCtx ctx, int fd, cchar *name, int omode) |
Attach to an existing file descriptor. | |
void | mprDisableFileBuffering(MprFile *file) |
Disable file buffering. | |
int | mprEnableFileBuffering(MprFile *file, int size, int maxSize) |
Enable file buffering. | |
int | mprFlush(MprFile *file) |
Flush any buffered write data. | |
int | mprGetc(MprFile *file) |
Read a character from the file. | |
MprOffset | mprGetFilePosition(MprFile *file) |
Return the current file position. | |
MprOffset | mprGetFileSize(MprFile *file) |
Get the size of the file. | |
char* | mprGets(MprFile *file, char *buf, uint size) |
Read a line from the file. | |
MprFile* | mprOpen(MprCtx ctx, cchar *filename, int omode, int perms) |
Open a file. | |
int | mprPeekc(MprFile *file) |
Non-destructively read a character from the file. | |
int | mprPutc(MprFile *file, int c) |
Write a character to the file. | |
int | mprPuts(MprFile *file, cchar *str) |
Write a string to the file. | |
int | mprRead(MprFile *file, void *buf, uint size) |
Read data from a file. | |
long | mprSeek(MprFile *file, int seekType, long distance) |
Seek the I/O pointer to a new location in the file. | |
int | mprWrite(MprFile *file, cvoid *buf, uint count) |
Write data to a file. | |
int | mprWriteFormat(MprFile *file, cchar *fmt, ...) |
Write formatted data to a file. | |
int | mprWriteString(MprFile *file, cchar *str) |
Write a string to a file. | |
MprHash* | mprAddDuplicateHash(MprHashTable *table, cchar *key, cvoid *ptr) |
Add a duplicate symbol value into the hash table. | |
MprHash* | mprAddHash(MprHashTable *table, cchar *key, cvoid *ptr) |
Add a symbol value into the hash table. | |
MprHashTable* | mprCopyHash(MprCtx ctx, MprHashTable *table) |
Copy a hash table. | |
MprHashTable* | mprCreateHash(MprCtx ctx, int hashSize) |
Create a hash table. | |
MprHash* | mprGetFirstHash(MprHashTable *table) |
Return the first symbol in a symbol entry. | |
int | mprGetHashCount(MprHashTable *table) |
Return the count of symbols in a symbol entry. | |
MprHash* | mprGetNextHash(MprHashTable *table, MprHash *last) |
Return the next symbol in a symbol entry. | |
cvoid* | mprLookupHash(MprHashTable *table, cchar *key) |
Lookup a symbol in the hash table. | |
MprHash* | mprLookupHashEntry(MprHashTable *table, cchar *key) |
Lookup a symbol in the hash table and return the hash entry. | |
int | mprRemoveHash(MprHashTable *table, cchar *key) |
Remove a symbol entry from the hash table. | |
void | mprError(MprCtx ctx, cchar *fmt, ...) |
Log an error message. | |
void | mprFatalError(MprCtx ctx, cchar *fmt, ...) |
Log a fatal error message and exit. | |
MprLogHandler | mprGetLogHandler(MprCtx ctx) |
Get the current MPR debug log handler. | |
void | mprLog(MprCtx ctx, int level, cchar *fmt, ...) |
Write a message to the diagnostic log file. | |
void | mprMemoryError(MprCtx ctx, cchar *fmt, ...) |
Log a memory error message. | |
void | mprRawLog(MprCtx ctx, int level, cchar *fmt, ...) |
Write a raw log message to the diagnostic log file. | |
void | mprSetLogHandler(MprCtx ctx, MprLogHandler handler, void *handlerData) |
Set an MPR debug log handler. | |
void | mprSetLogLevel(MprCtx ctx, int level) |
Set the current logging level. | |
void | mprStaticAssert(cchar *loc, cchar *msg) |
Output an assertion failed message. | |
void | mprStaticError(MprCtx ctx, cchar *fmt, ...) |
Write a message to the diagnostic log file without allocating any memory. | |
void | mprUserError(MprCtx ctx, cchar *fmt, ...) |
Display an error message to the user. | |
MprModule* | mprCreateModule(MprCtx ctx, cchar *name, cchar *version, void *moduleData, MprModuleProc start, MprModuleProc stop) |
Create a module. | |
cchar* | mprGetModuleSearchPath(MprCtx ctx) |
Get the module search path. | |
MprModule* | mprLoadModule(MprCtx ctx, cchar *filename, cchar *entryPoint) |
Load a module. | |
MprModule* | mprLookupModule(MprCtx ctx, cchar *name) |
Lookup a module. | |
void | mprSetModuleSearchPath(MprCtx ctx, char *searchPath) |
Set the module search path. | |
void | mprUnloadModule(MprModule *mp) |
Unload a module. | |
void | mprCloseSocket(MprSocket *sp, bool graceful) |
Close a socket. | |
MprSocket* | mprCreateSocket(MprCtx ctx, struct MprSsl *ssl) |
Create a socket. | |
int | mprFlushSocket(MprSocket *sp) |
Flush a socket. | |
bool | mprGetSocketBlockingMode(MprSocket *sp) |
Get the socket blocking mode. | |
int | mprGetSocketError(MprSocket *sp) |
Get a socket error code. | |
int | mprGetSocketFd(MprSocket *sp) |
Get the socket file descriptor. | |
int | mprGetSocketPort(MprSocket *sp) |
Get the port used by a socket. | |
bool | mprHasSocketPendingData(MprSocket *sp) |
Test if the socket has buffered read data. | |
bool | mprIsSocketEof(MprSocket *sp) |
Test if the other end of the socket has been closed. | |
bool | mprIsSocketSecure(MprSocket *sp) |
Determine if the socket is secure. | |
int | mprOpenClientSocket(MprSocket *sp, cchar *hostName, int port, int flags) |
Open a client socket. | |
int | mprOpenServerSocket(MprSocket *sp, cchar *ipAddr, int port, MprSocketAcceptProc acceptFn, void *data, int flags) |
Open a server socket. | |
int | mprReadSocket(MprSocket *sp, void *buf, int size) |
Read from a socket. | |
int | mprSetSocketBlockingMode(MprSocket *sp, bool on) |
Set the socket blocking mode. | |
void | mprSetSocketCallback(MprSocket *sp, MprSocketProc fn, void *data, int mask, int priority) |
Set the socket callback. | |
void | mprSetSocketEventMask(MprSocket *sp, int mask) |
Define the events of interest for a socket. | |
int | mprSetSocketNoDelay(MprSocket *sp, bool on) |
Set the socket delay mode. | |
int | mprWriteSocket(MprSocket *sp, void *buf, int len) |
Write to a socket. | |
int | mprWriteSocketString(MprSocket *sp, cchar *str) |
Write to a string to a socket. | |
int | mprWriteSocketVector(MprSocket *sp, MprIOVec *iovec, int count) |
Write a vector to a socket. | |
MprCond* | mprCreateCond(MprCtx ctx) |
Create a condition lock variable. | |
MprMutex* | mprCreateLock(MprCtx ctx) |
Create a Mutex lock object. | |
MprSpin* | mprCreateSpinLock(MprCtx ctx) |
Create a spin lock lock object. | |
void | mprGlobalLock(MprCtx ctx) |
Globally lock the application. | |
void | mprGlobalUnlock(MprCtx ctx) |
Unlock the global mutex. | |
MprMutex* | mprInitLock(MprCtx ctx, MprMutex *mutex) |
Initialize a statically allocated Mutex lock object. | |
MprSpin* | mprInitSpinLock(MprCtx ctx, MprSpin *lock) |
Initialize a statically allocated spinlock object. | |
void | mprLock(MprMutex *lock) |
Lock access. | |
void | mprSignalCond(MprCond *cond) |
Signal a condition lock variable. | |
void | mprSpinLock(MprSpin *lock) |
Lock a spinlock. | |
void | mprSpinUnlock(MprSpin *lock) |
Unlock a spinlock. | |
bool | mprTryLock(MprMutex *lock) |
Attempt to lock access. | |
bool | mprTrySpinLock(MprSpin *lock) |
Attempt to lock access on a spin lock. | |
void | mprUnlock(MprMutex *lock) |
Unlock a mutex. | |
int | mprWaitForCond(MprCond *cond, int timeout) |
Wait for a condition lock variable. | |
int | mprWaitForCondWithService(MprCond *cond, int timeout) |
Wait for a condition lock variable and pump events while waiting. | |
MprThread* | mprCreateThread(MprCtx ctx, cchar *name, MprThreadProc proc, void *data, int priority, int stackSize) |
Create a new thread. | |
MprOsThread | mprGetCurrentOsThread() |
Get the O/S thread. | |
MprThread* | mprGetCurrentThread(MprCtx ctx) |
Get the currently executing thread. | |
cchar* | mprGetThreadName(MprThread *thread) |
Get the thread name. | |
int | mprGetThreadPriority(MprThread *thread) |
Get the thread priroity. | |
void | mprSetCurrentThreadPriority(MprCtx ctx, int priority) |
Set the thread priroity for the current thread. | |
void | mprSetThreadPriority(MprThread *thread, int priority) |
Set the thread priroity. | |
int | mprStartThread(MprThread *thread) |
Start a thread. | |
MprWaitHandler* | mprCreateWaitHandler(MprCtx ctx, int fd, int mask, MprWaitProc proc, void *data, int priority, int flags) |
Create a wait handler. | |
void | mprDisableWaitEvents(MprWaitHandler *wp) |
Disable wait events. | |
void | mprEnableWaitEvents(MprWaitHandler *wp) |
Enable wait events. | |
void | mprRecallWaitHandler(MprWaitHandler *wp) |
Recall a wait handler. | |
void | mprSetWaitCallback(MprWaitHandler *wp, MprWaitProc proc, int mask) |
Define the wait handler callback. | |
void | mprSetWaitEvents(MprWaitHandler *wp, int desiredMask, int disableMask) |
Define the events of interest for a wait handler. | |
int | mprGetAvailableWorkers(MprCtx ctx) |
Get the count of available worker threads Return the count of free threads in the worker thread pool. | |
int | mprGetMaxWorkers(MprCtx ctx) |
Get the maximum count of worker pool threads Get the maximum limit of worker pool threads. | |
void | mprSetMaxWorkers(MprCtx ctx, int count) |
Set the maximum count of worker threads Set the maximum number of worker pool threads for the MPR. | |
void | mprSetMinWorkers(MprCtx ctx, int count) |
Set the minimum count of worker threads Set the count of threads the worker pool will have. |
Typedefs
MprAllocNotifier | Memory allocation error callback. |
MprBufProc | Buffer refill callback function. |
MprCtx | Memory context type. |
MprDestructor | Mpr memory block destructors prototype. |
MprEventProc | Event callback function. |
MprHttpProc | Http callback procedure Must not delete the http instance in the callback. |
MprListCompareProc | List comparison procedure for sorting. |
MprLogHandler | Log handler callback type. |
MprModuleEntry | Loadable module entry point signature. |
MprModuleProc | Module start/stop point function signature. |
MprSocketAcceptProc | Socket connection acceptance callback procedure. |
MprSocketProc | Socket I/O callback procedure. |
MprTime | Mpr time structure. |
MprWorkerProc | Worker thread callback signature. |
MprBufProc | Buffer refill callback function. |
MprTime | Mpr time structure. |
MprLogHandler | Log handler callback type. |
MprModuleEntry | Loadable module entry point signature. |
MprBlk | Memory Allocation Block Header. |
MprCond | Condition variable for single and multi-thread synchronization. |
MprDirEntry | Directory entry description. |
MprFileSystem | File system service. |
MprHashTable | Hash table control structure. |
MprHttpRequest | HTTP Per-request structure. |
MprHttpResponse | HTTP Per-response structure. |
MprKeyValue | Key value pairs for use with MprList or MprHash. |
MprMutex | Multithreading lock control structure. |
MprSpin | Multithreading spin lock control structure. |
MprString | Safe String Module. |
MprThreadLocal | Thread local data storage. |
Defines
#define | MPR_BACKGROUND_PRIORITY 15 |
May only get CPU if idle. | |
#define | MPR_BUF_INCR 4096 |
Default buffer growth inc. | |
#define | MPR_BUFSIZE 4096 |
Reasonable size for buffers. | |
#define | MPR_CRITICAL_PRIORITY 99 |
May not yield. | |
#define | MPR_DEFAULT_ALLOC 64 |
Default small alloc size. | |
#define | MPR_DEFAULT_HASH_SIZE 23 |
Default size of hash table. | |
#define | MPR_DEFAULT_MAX_THREADS 20 |
Default max threads. | |
#define | MPR_DEFAULT_MIN_THREADS 0 |
Default min threads. | |
#define | MPR_DEFAULT_STACK (64 * 1024) |
Default thread stack size (64K). | |
#define | MPR_ERR -1 |
Default error code. | |
#define | MPR_ERR_ABORTED -2 |
Action aborted. | |
#define | MPR_ERR_ALREADY_EXISTS -3 |
Item already exists. | |
#define | MPR_ERR_BAD_ARGS -4 |
Bad arguments or paramaeters. | |
#define | MPR_ERR_BAD_FORMAT -5 |
Bad input format. | |
#define | MPR_ERR_BAD_STATE -7 |
Module is in a bad state. | |
#define | MPR_ERR_BAD_SYNTAX -8 |
Input has bad syntax. | |
#define | MPR_ERR_CANT_ACCESS -12 |
Can't access the file or resource. | |
#define | MPR_ERR_CANT_CREATE -14 |
Can't create the file or resource. | |
#define | MPR_ERR_CANT_OPEN -16 |
Can't open the file or resource. | |
#define | MPR_ERR_CANT_READ -17 |
Can't read from the file or resource. | |
#define | MPR_ERR_CANT_WRITE -18 |
Can't write to the file or resource. | |
#define | MPR_ERR_GENERAL -1 |
General error. | |
#define | MPR_ERR_NO_MEMORY -30 |
Memory allocation error. | |
#define | MPR_ERR_NOT_INITIALIZED -22 |
Module or resource is not initialized. | |
#define | MPR_ERR_OK 0 |
Standard MPR return and error codes. | |
#define | MPR_ERR_READ_ONLY -24 |
The operation timed out. | |
#define | MPR_ERROR 1 |
Standard logging trace levels are 0 to 9 with 0 being the most verbose. | |
#define | MPR_EVENT_CONTINUOUS 0x1 |
Auto reschedule the event. | |
#define | MPR_EVENT_PRIORITY 50 |
Normal priority. | |
#define | MPR_EVENT_RUNNING 0x4 |
Event currently executing. | |
#define | MPR_EVENT_THREAD 0x2 |
Run proc using worker thread. | |
#define | MPR_HTTP_BUFSIZE 4096 |
HTTP buffer size. | |
#define | MPR_HTTP_MAX_PASS 64 |
Size of password. | |
#define | MPR_HTTP_MAX_SECRET 32 |
Random bytes to use. | |
#define | MPR_HTTP_MAX_USER 64 |
Size of user name. | |
#define | MPR_HTTP_REQ_CHUNK_EMITTED 0x1 |
Chunk boundary emitted. | |
#define | MPR_LIST_INCR 8 |
Default list growth inc. | |
#define | MPR_MAX_ARGC 128 |
Reasonable max of args. | |
#define | MPR_MAX_BUF 4194304 |
Max buffer size. | |
#define | MPR_MAX_FNAME 256 |
Reasonable filename size. | |
#define | MPR_MAX_LOG_STRING 512 |
Maximum log message. | |
#define | MPR_MAX_PATH 512 |
Reasonable path name size. | |
#define | MPR_MAX_STRING 1024 |
Maximum (stack) string size. | |
#define | MPR_MAX_URL 512 |
Max URL size. | |
#define | MPR_NORMAL_PRIORITY 50 |
Normal (default) priority. | |
#define | MPR_REQUEST_PRIORITY 50 |
Normal priority. | |
#define | MPR_SECURE_CLIENT ((struct MprSsl*) 1) |
Flag for mprCreateSocket to use the default SSL provider. | |
#define | MPR_SERVICE_EVENTS 0x1 |
Service events. | |
#define | MPR_SERVICE_IO 0x2 |
Service I/O events. | |
#define | MPR_SERVICE_ONE_THING 0x4 |
Wait for one event or one I/O. | |
#define | MPR_SOCKET_BLOCK 0x1 |
Use blocking I/O. | |
#define | MPR_SOCKET_BROADCAST 0x2 |
Broadcast mode. | |
#define | MPR_SOCKET_CLIENT 0x800 |
Socket is a client. | |
#define | MPR_SOCKET_CLOSED 0x4 |
MprSocket has been closed. | |
#define | MPR_SOCKET_CONNECTING 0x8 |
MprSocket has been closed. | |
#define | MPR_SOCKET_DATAGRAM 0x10 |
Use datagrams. | |
#define | MPR_SOCKET_EOF 0x20 |
Seen end of file. | |
#define | MPR_SOCKET_LISTENER 0x40 |
MprSocket is server listener. | |
#define | MPR_SOCKET_NODELAY 0x100 |
Disable Nagle algorithm. | |
#define | MPR_SOCKET_NOREUSE 0x80 |
Dont set SO_REUSEADDR option. | |
#define | MPR_SOCKET_PENDING 0x1000 |
Pending buffered read data. | |
#define | MPR_SOCKET_RUNNING 0x2000 |
Socket is running callback. | |
#define | MPR_SOCKET_THREAD 0x400 |
Process callbacks on a worker thread. | |
#define | MPR_SSL_BUFSIZE 4096 |
SSL has 16K max. | |
#define | MPR_TICKS_PER_SEC 1000 |
Time ticks per second. | |
#define | MPR_TIMEOUT_CMD 60000 |
Command Request timeout (60 sec). | |
#define | MPR_TIMEOUT_HANDLER 10000 |
Wait period when removing a wait handler. | |
#define | MPR_TIMEOUT_HTTP 60000 |
HTTP Request timeout (60 sec). | |
#define | MPR_TIMEOUT_LINGER 2000 |
Close socket linger timeout. | |
#define | MPR_TIMEOUT_LOG_STAMP 3600000 |
Time between log time stamps (1 hr). | |
#define | MPR_TIMEOUT_PRUNER 600000 |
Time between pruner runs (10 min). | |
#define | MPR_TIMEOUT_SOCKETS 10000 |
General sockets timeout. | |
#define | MPR_TIMEOUT_START_TASK 2000 |
Time to start tasks running. | |
#define | MPR_TIMEOUT_STOP 5000 |
Wait when stopping resources. | |
#define | MPR_TIMEOUT_STOP_TASK 10000 |
Time to stop or reap tasks. | |
#define | MPR_TIMEOUT_STOP_THREAD 10000 |
Time to stop running threads. | |
#define | MPR_WORKER_PRIORITY 50 |
Normal priority. | |
#define | MPR_XML_BUFSIZE 4096 |
XML read buffer size. |
Mpr
Primary MPR application control structure.
- Description:
- The Mpr structure stores critical application state information and is the root memory allocation context block. It is used as the MprCtx context for other memory allocations and is thus the ultimate parent of all allocated memory.
- API Stability:
- Evolving.
- See Also:
- mprBreakpoint, mprCreateEx, mprGetError, mprGetOsError, mprIsExiting, mprSetDebugMode, mprSignalExit, mprTerminate
- Fields:
-
Trigger a breakpoint.
- Description:
- Triggers a breakpoint and traps to the debugger.
- See Also:
- mprCreateEx, mprGetError, mprGetOsError, mprIsExiting, mprSetDebugMode, mprSignalExit, mprTerminate
Create an instance of the MPR.
- Description:
- Initializes the MPR and creates an Mpr control object. The Mpr Object manages Mpr facilities and is the top level memory context. It may be used wherever a MprCtx parameter is required. This function must be called prior to calling any other Mpr API.
- Parameters:
-
argc Count of command line args. argv Command line arguments for the application. Arguments may be passed into the Mpr for retrieval by the unit test framework. cback Memory allocation failure notification callback.
- Returns:
- Returns a pointer to the Mpr object.
- API Stability:
- Evolving.
Create an instance of the MPR.
- Description:
- Alternate API to create and initialize the MPR. The Mpr object manages Mpr facilities and is the top level memory context. It may be used wherever a MprCtx parameter is required. This function, or mprCreate must be called prior to calling any other Mpr API.
- Parameters:
-
argc Count of arguments supplied in argv. argv Program arguments. The MPR can store the program arguments for retrieval by other parts of the program. cback Callback function to be invoked on memory allocation errors. Set to null if not required. shell Optional reference to an O/S implementation dependent shell object. Used by Brew.
- Returns:
- Returns a pointer to the Mpr object.
- API Stability:
- Evolving.
Get the debug mode.
- Description:
- Returns whether the debug mode is enabled. Some modules observe debug mode and disable timeouts and timers so that single-step debugging can be used.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- Returns true if debug mode is enabled, otherwise returns false.
- API Stability:
- Evolving.
Return the error code for the most recent system or library operation.
- Description:
- Returns an error code from the most recent system call. This will be mapped to be either a POSIX error code or an MPR error code.
- Returns:
- The mapped error code.
- API Stability:
- Evolving.
Return the O/S error code.
- Description:
- Returns an O/S error code from the most recent system call. This returns errno on Unix systems or GetLastError() on Windows.
- Returns:
- The O/S error code.
- API Stability:
- Evolving.
- See Also:
- mprBreakpoint, mprCreateEx, mprGetError, mprIsExiting, mprSetDebugMode, mprSignalExit, mprTerminate
Determine if the MPR should exit.
- Description:
- Returns true if the MPR should exit gracefully.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- True if the App has been instructed to exit.
- API Stability:
- Evolving.
- See Also:
- mprBreakpoint, mprCreateEx, mprGetError, mprGetOsError, mprSetDebugMode, mprSignalExit, mprTerminate
Signal the MPR to exit gracefully.
- Description:
- Set the must exit flag for the MPR.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- API Stability:
- Evolving.
- See Also:
- mprBreakpoint, mprCreateEx, mprGetError, mprGetOsError, mprIsExiting, mprSetDebugMode, mprTerminate
Terminate the MPR.
- Description:
- Terminates the MPR and disposes of all allocated resources. The mprTerminate function will recursively free all memory allocated by the MPR.
- Parameters:
-
ctx Any memory context object returned by mprAlloc. graceful Shutdown gracefully waiting for all events to drain. Otherise exit immediately without waiting for any threads or events to complete.
- API Stability:
- Evolving.
- See Also:
- mprBreakpoint, mprCreateEx, mprGetError, mprGetOsError, mprIsExiting, mprSetDebugMode, mprSignalExit
MprBuf
Dynamic Buffer Module.
- Description:
- MprBuf is a flexible, dynamic growable buffer structure. It has start and end pointers to the data buffer which act as read/write pointers. Routines are provided to get and put data into and out of the buffer and automatically advance the appropriate start/end pointer. By definition, the buffer is empty when the start pointer == the end pointer. Buffers can be created with a fixed size or can grow dynamically as more data is added to the buffer.
For performance, the specification of MprBuf is deliberately exposed. All members of MprBuf are implicitly public. However, it is still recommended that wherever possible, you use the accessor routines provided.
- API Stability:
- Evolving.
- See Also:
- MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
- Fields:
-
Add a null character to the buffer contents.
- Description:
- Add a null byte but do not change the buffer content lengths. The null is added outside the "official" content length. This is useful when calling mprGetBufStart and using the returned pointer as a "C" string pointer.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Adjust the buffer end position.
- Description:
- Adjust the buffer start end position by the specified amount. This is typically used to advance the end position as content is appended to the buffer. Adjusting the start or end position will change the value returned by mprGetBufLength. If using the mprPutBlock or mprPutChar routines, adjusting the end position is done automatically.
- Parameters:
-
buf Buffer created via mprCreateBuf. count Positive or negative count of bytes to adjust the start position.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Adjust the buffer start position.
- Description:
- Adjust the buffer start position by the specified amount. This is typically used to advance the start position as content is consumed. Adjusting the start or end position will change the value returned by mprGetBufLength. If using the mprGetBlock or mprGetChar routines, adjusting the start position is done automatically.
- Parameters:
-
buf Buffer created via mprCreateBuf. count Positive or negative count of bytes to adjust the start position.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Compact the buffer contents.
- Description:
- Compact the buffer contents by copying the contents down to start the the buffer origin.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Create a new buffer.
- Description:
- Create a new buffer. Use mprFree to free the buffer.
- Parameters:
-
ctx Any memory context allocated by the MPR. initialSize Initial size of the buffer. maxSize Maximum size the buffer can grow to.
- Returns:
- A new buffer.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Flush the buffer contents.
- Description:
- Discard the buffer contents and reset the start end content pointers.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get a block of data from the buffer.
- Description:
- Get a block of data from the buffer start and advance the start position. If the requested length is greater than the available buffer content, then return whatever data is available.
- Parameters:
-
buf Buffer created via mprCreateBuf. blk Destination block for the read data. count Count of bytes to read from the buffer.
- Returns:
- The count of bytes rread into the block or -1 if the buffer is empty.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get a reference to the end of the buffer contents.
- Description:
- Get a pointer to the location immediately after the end of the buffer contents.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- Pointer to the end of the buffer data contents. Points to the location one after the last data byte.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get the buffer content length.
- Description:
- Get the length of the buffer contents. This is not the same as the buffer size which may be larger.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- The length of the content stored in the buffer.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get the origin of the buffer content storage.
- Description:
- Get a pointer to the start of the buffer content storage. This may not be equal to the start of the buffer content if mprAdjustBufStart has been called. Use mprGetBufSize to determine the length of the buffer content storage array.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- A pointer to the buffer content storage.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get the buffer refill procedure.
- Description:
- Return the buffer refill callback function.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- The refill call back function if defined.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get the current size of the buffer content storage.
- Description:
- This returns the size of the memory block allocated for storing the buffer contents.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- The size of the buffer content storage.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get the space available to store content.
- Description:
- Get the number of bytes available to store content in the buffer.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- The number of bytes available.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get the start of the buffer contents.
- Description:
- Get a pointer to the start of the buffer contents. Use mprGetBufLength to determine the length of the content. Use mprGetBufEnd to get a pointer to the location after the end of the content.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- Pointer to the start of the buffer data contents.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Get a character from the buffer.
- Description:
- Get the next byte from the buffer start and advance the start position.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- The character or -1 if the buffer is empty.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Grow the buffer.
- Description:
- Grow the storage allocated for content for the buffer. The new size must be less than the maximum limit specified via mprCreateBuf or mprSetBufSize.
- Parameters:
-
buf Buffer created via mprCreateBuf. count Count of bytes by which to grow the buffer content size.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Insert a character into the buffer.
- Description:
- Insert a character into to the buffer prior to the current buffer start point.
- Parameters:
-
buf Buffer created via mprCreateBuf. c Character to append.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Peek at the last character in the buffer.
- Description:
- Non-destructively return the last character from just prior to the end position in the buffer. The character is returned and the end position is not altered.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Peek at the next character in the buffer.
- Description:
- Non-destructively return the next character from the start position in the buffer. The character is returned and the start position is not altered.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Put a block to the buffer.
- Description:
- Append a block of data to the buffer at the end position and increment the end pointer.
- Parameters:
-
buf Buffer created via mprCreateBuf. ptr Block to append. size Size of block to append.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Put a character to the buffer.
- Description:
- Append a character to the buffer at the end position and increment the end pointer.
- Parameters:
-
buf Buffer created via mprCreateBuf. c Character to append.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Put a formatted string to the buffer.
- Description:
- Format a string and Append to the buffer at the end position and increment the end pointer.
- Parameters:
-
buf Buffer created via mprCreateBuf. fmt Printf style format string. ... Variable arguments for the format string.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Put an integer to the buffer.
- Description:
- Append a integer to the buffer at the end position and increment the end pointer.
- Parameters:
-
buf Buffer created via mprCreateBuf. i Integer to append to the buffer.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Put a string to the buffer.
- Description:
- Append a null terminated string to the buffer at the end position and increment the end pointer.
- Parameters:
-
buf Buffer created via mprCreateBuf. str String to append.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Refill the buffer with data.
- Description:
- Refill the buffer by calling the refill procedure specified via mprSetBufRefillProc.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Reset the buffer.
- Description:
- If the buffer is empty, reset the buffer start and end pointers to the beginning of the buffer.
- Parameters:
-
buf Buffer created via mprCreateBuf.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Set the maximum buffer size.
- Description:
- Update the maximum buffer size set when the buffer was created.
- Parameters:
-
buf Buffer created via mprCreateBuf. maxSize New maximum size the buffer can grow to.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Set the buffer refill procedure.
- Description:
- Define a buffer refill procedure. The MprBuf module will not invoke or manage this refill procedure. It is simply stored to allow upper layers to use and provide their own auto-refill mechanism.
- Parameters:
-
buf Buffer created via mprCreateBuf. fn Callback function to store. arg Callback data argument.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufSize, mprStealBuf
Set the buffer size.
- Description:
- Set the current buffer content size and maximum size limit. Setting a current size will immediately grow the buffer to be this size. If the size is less than the current buffer size, the requested size will be ignored. ie. this call will not shrink the buffer. Setting a maxSize will define a maximum limit for how big the buffer contents can grow. Set either argument to -1 to be ignored.
- Parameters:
-
buf Buffer created via mprCreateBuf. size Size to immediately make the buffer. If size is less than the current buffer size, it will be ignored. Set to -1 to ignore this parameter. maxSize Maximum size the buffer contents can grow to.
- Returns:
- Zero if successful and otherwise a negative error code.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprStealBuf
Steal the buffer memory from a buffer.
- Description:
- Steal ownership of the buffer memory from the buffer structure. All MPR memory is owned by a memory context and the contents of the buffer is owned by the MprBuf object. Stealing the buffer content memory is useful to preserve the buffer contents after the buffer is freed.
- Parameters:
-
ctx Memory context to won the memory for the buffer. buf Buffer created via mprCreateBuf.
- Returns:
- Pointer to the buffer contents. Use mprGetBufLength before calling mprStealBuf to determine the resulting size of the contents.
- See Also:
- MprBuf, MprBufProc, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize
MprCmd
Command execution Service.
- Description:
- The MprCmd service enables execution of local commands. It uses three full-duplex pipes to communicate read, write and error data with the command.
- API Stability:
- Evolving.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
- Fields:
-
Close the command channel.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to close. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR.
- See Also:
- mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Create a new Command object.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc.
- Returns:
- A newly allocated MprCmd object. Use mprFree to close and free.
- See Also:
- mprCloseCmdFd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Disable command I/O events.
This disables events on a given channel- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to close. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Disconnect a command its underlying I/O channels.
This is used to prevent further I/O wait events while still preserving the MprCmd object- Parameters:
-
cmd MprCmd object created via mprCreateCmd.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Enable command I/O events.
This enables events on a given channel- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to close. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Get the underlying buffer for a channel.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to close. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR.
- Returns:
- A reference to the MprBuf buffer structure.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Get the command exit status.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. status Reference to an integer to receive the command exit status. This is typically zero for success, but this is platform specific.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Get the underlying file descriptor for an I/O channel.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to close. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR.
- Returns:
- The file descriptor.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Test if the command is still running.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd.
- Returns:
- True if the command is still running.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Make the I/O channels to send and receive data to and from the command.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Poll for I/O on the command pipes.
This is only used on windows which can't adequately detect EOF on a named pipe- Parameters:
-
cmd MprCmd object created via mprCreateCmd. timeout Time in milliseconds to wait for the command to complete and exit.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Make the I/O channels to send and receive data to and from the command.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to read from. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR. buf Buffer to read into. bufsize Size of buffer.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Reap the command.
This waits for and collect the command exit status- Parameters:
-
cmd MprCmd object created via mprCreateCmd. timeout Time in milliseconds to wait for the command to complete and exit.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Run a command using a string command line.
This starts the command via mprStartCmd() and waits for its completion- Parameters:
-
cmd MprCmd object created via mprCreateCmd. command Command line to run. out Reference to a string to receive the stdout from the command. Caller must free. err Reference to a string to receive the stderr from the command. Caller must free. flags Flags to modify execution. Valid flags are: MPR_CMD_NEW_SESSION Create a new session on Unix MPR_CMD_SHOW Show the commands window on Windows MPR_CMD_IN Connect to stdin.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Run a command using an argv[] array of arguments.
This invokes mprStartCmd() and waits for its completion- Parameters:
-
cmd MprCmd object created via mprCreateCmd. argc Count of arguments in argv. argv Command arguments array. out Reference to a string to receive the stdout from the command. Caller must free. err Reference to a string to receive the stderr from the command. Caller must free. flags Flags to modify execution. Valid flags are: MPR_CMD_NEW_SESSION Create a new session on Unix MPR_CMD_SHOW Show the commands window on Windows MPR_CMD_IN Connect to stdin.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Define a callback to be invoked to receive response data from the command.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. callback Function of the signature MprCmdProc which will be invoked for receive notification for data from the commands stdout and stderr channels. MprCmdProc has the signature: int callback(MprCmd *cmd, int channel, void *data) {}. data User defined data to be passed to the callback.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Set the home directory for the command.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. dir String directory path name.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Set the command environment.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. env Array of environment strings. Each environment string should be of the form: "KEY=VALUE". The array must be null terminated.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprStartCmd, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Start the command.
This starts the command but does not wait for its completion. Once started, mprWriteCmdPipe can be used to write to the command and response data can be received via mprReadCmdPipe- Parameters:
-
cmd MprCmd object created via mprCreateCmd. argc Count of arguments in argv. argv Command arguments array. envp Array of environment strings. Each environment string should be of the form: "KEY=VALUE". The array must be null terminated. flags Flags to modify execution. Valid flags are: MPR_CMD_NEW_SESSION Create a new session on Unix MPR_CMD_SHOW Show the commands window on Windows MPR_CMD_IN Connect to stdin.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStopCmd, mprWaitForCmd, mprWriteCmdPipe
Stop the command.
The command is immediately killed- Parameters:
-
cmd MprCmd object created via mprCreateCmd.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprWaitForCmd, mprWriteCmdPipe
Wait for the command to complete.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. timeout Time in milliseconds to wait for the command to complete and exit.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWriteCmdPipe
Write data to an I/O channel.
- Parameters:
-
cmd MprCmd object created via mprCreateCmd. channel Channel number to read from. Should be either MPR_CMD_STDIN, MPR_CMD_STDOUT or MPR_CMD_STDERR. buf Buffer to read into. bufsize Size of buffer.
- See Also:
- mprCloseCmdFd, mprCreateCmd, mprDisableCmdEvents, mprDisconnectCmd, mprEnableCmdEvents, mprGetCmdBuf, mprGetCmdExitStatus, mprGetCmdFd, mprIsCmdRunning, mprMakeCmdIO, mprPollCmdPipes, mprReadCmdPipe, mprReapCmd, mprRunCmd, mprRunCmdV, mprSetCmdCallback, mprSetCmdDir, mprSetCmdEnv, mprStartCmd, mprStopCmd, mprWaitForCmd
MprDate
Date and Time Service.
- API Stability:
- Evolving.
- Fields:
-
Decode a time value into a tokenized local time value.
- Description:
- Safe replacement for localtime. This call converts the time value to local time and formats the as a struct tm.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. timep Pointer to a tm structure to hold the result. time Time to format.
- Returns:
- Returns a pointer to the tmBuf.
- See Also:
- MprTime, mprDecodeUniversalTime, mprFormatLocalTime, mprFormatTime
Decode a time value into a tokenized UTC time structure.
- Description:
- Safe replacement for gmtime. This call converts the supplied time value to UTC time and parses the result into a tm structure.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. timep Pointer to a tm structure to hold the result. time The time to format.
- Returns:
- The tm structure reference.
- See Also:
- MprTime, mprDecodeLocalTime, mprFormatLocalTime, mprFormatTime
Convert a time value to local time and format as a string.
- Description:
- Safe replacement for ctime. This call formats the time value supplied via timep.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. time Time to format. Use mprGetTime to retrieve the current time.
- Returns:
- The formatting time string.
- See Also:
- MprTime, mprDecodeLocalTime, mprDecodeUniversalTime, mprFormatTime
Format a time value as a local time.
- Description:
- This call formats the time value supplied via timep.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. fmt The time format to use. timep The time value to format.
- Returns:
- The formatting time string. Caller should free.
Return the time remaining until a timeout has elapsed.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. mark Starting time stamp. timeout Time in milliseconds.
- Returns:
- Time in milliseconds until the timeout elapses.
Get the system time.
- Description:
- Get the system time in milliseconds.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- Returns:
- The time in milliseconds since boot.
MprFile
File I/O Module.
- Description:
- MprFile is the cross platform File I/O abstraction control structure. An instance will be created when a file is created or opened via mprOpen.
- API Stability:
- Evolving.
- See Also:
- mprDisableFileBuffering, mprEnableFileBuffering, mprFlush, mprGetFilePosition, mprGetFileSize, mprGetc, mprGets, mprOpen, mprPeekc, mprPutc, mprPuts, mprRead, mprSeek, mprWrite, mprWriteFormat, mprWriteString
- Fields:
-
Attach to an existing file descriptor.
- Description:
- Attach a file to an open file decriptor and return a file object.
- Parameters:
-
ctx Any memory context allocated by the MPR. fd File descriptor to attach to. name Descriptive name for the file. omode Posix style file open mode mask. The open mode may contain the following mask values ored together: - O_RDONLY Open read only
- O_WRONLY Open write only
- O_RDWR Open for read and write
- O_CREAT Create or re-create
- O_TRUNC Truncate
- O_BINARY Open for binary data
- O_TEXT Open for text data
- O_EXCL Open with an exclusive lock
- O_APPEND Open to append
- Returns:
- Returns an MprFile object to use in other file operations.
Disable file buffering.
- Description:
- Disable any buffering of data when using the buffer.
- Parameters:
-
file File instance returned from mprOpen.
Enable file buffering.
- Description:
- Enable data buffering when using the buffer.
- Parameters:
-
file File instance returned from mprOpen. size Size to allocate for the buffer. maxSize Maximum size the data buffer can grow to.
Flush any buffered write data.
- Description:
- Write buffered write data and then reset the internal buffers.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen.
- Returns:
- Zero if successful, otherwise a negative MPR error code.
Read a character from the file.
- Description:
- Read a single character from the file and advance the read position.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen.
- Returns:
- If successful, return the character just read. Otherwise return a negative MPR error code. End of file is signified by reading 0.
Return the current file position.
- Description:
- Return the current read/write file position.
- Parameters:
-
file A file object returned from mprOpen.
- Returns:
- The current file offset position if successful. Returns a negative MPR error code on errors.
Get the size of the file.
- Description:
- Return the current file size.
- Parameters:
-
file A file object returned from mprOpen.
- Returns:
- The current file size if successful. Returns a negative MPR error code on errors.
Read a line from the file.
- Description:
- Read a single line from the file and advance the read position. Lines are delimited by the newline character. The newline is not included in the returned buffer.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. buf Pre-allocated buffer to contain the line of data. size Size of buf.
- Returns:
- The number of characters read into buf.
Open a file.
- Description:
- Open a file and return a file object.
- Parameters:
-
ctx Any memory context allocated by the MPR. filename String containing the filename to open or create. omode Posix style file open mode mask. The open mode may contain the following mask values ored together: - O_RDONLY Open read only
- O_WRONLY Open write only
- O_RDWR Open for read and write
- O_CREAT Create or re-create
- O_TRUNC Truncate
- O_BINARY Open for binary data
- O_TEXT Open for text data
- O_EXCL Open with an exclusive lock
- O_APPEND Open to append
perms Posix style file permissions mask.
- Returns:
- Returns an MprFile object to use in other file operations.
Non-destructively read a character from the file.
- Description:
- Read a single character from the file without advancing the read position.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen.
- Returns:
- If successful, return the character just read. Otherwise return a negative MPR error code. End of file is signified by reading 0.
Write a character to the file.
- Description:
- Writes a single character to the file. Output is buffered and is flushed as required or when mprClose is called.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. c Character to write.
- Returns:
- One if successful, otherwise returns a negative MPR error code on errors.
Write a string to the file.
- Description:
- Writes a string to the file. Output is buffered and is flushed as required or when mprClose is called.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. str String to write.
- Returns:
- The number of characters written to the file. Returns a negative MPR error code on errors.
Read data from a file.
- Description:
- Reads data from a file.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. buf Buffer to contain the read data. size Size of buf in characters.
- Returns:
- The number of characters read from the file. Returns a negative MPR error code on errors.
Seek the I/O pointer to a new location in the file.
- Description:
- Move the position in the file to/from which I/O will be performed in the file. Seeking prior to a read or write will cause the next I/O to occur at that location.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. seekType Seek type may be one of the following three values: - SEEK_SET Seek to a position relative to the start of the file
- SEEK_CUR Seek relative to the current position
- SEEK_END Seek relative to the end of the file
distance A positive or negative byte offset.
- Returns:
- The new file position if successful otherwise a negative MPR error code is returned.
Write data to a file.
- Description:
- Writes data to a file.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. buf Buffer containing the data to write. count Cound of characters in buf to write.
- Returns:
- The number of characters actually written to the file. Returns a negative MPR error code on errors.
Write formatted data to a file.
- Description:
- Writes a formatted string to a file.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. fmt Format string.
- Returns:
- The number of characters actually written to the file. Returns a negative MPR error code on errors.
Write a string to a file.
- Description:
- Writes a string to a file.
- Parameters:
-
file Pointer to an MprFile object returned via MprOpen. str String to write.
- Returns:
- The number of characters actually written to the file. Returns a negative MPR error code on errors.
MprHash
Hash table entry structure.
- Description:
- Each hash entry has a descriptor entry. This is used to manage the hash table link chains.
- See Also:
- mprAddDuplicateHash, mprAddHash, mprCopyHash, mprCreateHash, mprCreateKeyPair, mprFree, mprGetFirstHash, mprGetNextHash, mprLookupHash, mprLookupHashEntry, mprRemoveHash
- API Stability:
- Evolving.
- Fields:
-
Add a duplicate symbol value into the hash table.
- Description:
- Add a symbol to the hash which may clash with an existing entry. Duplicate symbols can be added to the hash, but only one may be retrieved via mprLookupHash. To recover duplicate entries walk the hash using mprGetNextHash.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable. key String key of the symbole entry to delete. ptr Arbitrary pointer to associate with the key in the table.
- Returns:
- Integer count of the number of entries.
Add a symbol value into the hash table.
- Description:
- Associate an arbitrary value with a string symbol key and insert into the symbol table.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable. key String key of the symbole entry to delete. ptr Arbitrary pointer to associate with the key in the table.
- Returns:
- Integer count of the number of entries.
Copy a hash table.
- Description:
- Create a new hash table and copy all the entries from an existing table.
- Parameters:
-
ctx Any memory context allocated by the MPR. table Symbol table returned via mprCreateSymbolTable.
- Returns:
- A new hash table initialized with the contents of the original hash table.
Create a hash table.
- Description:
- Creates a hash table that can store arbitrary objects associated with string key values.
- Parameters:
-
ctx Any memory context allocated by the MPR. hashSize Size of the hash table for the symbol table. Should be a prime number.
- Returns:
- Returns a pointer to the allocated symbol table. Caller should use mprFree to dispose of the table when complete.
Return the first symbol in a symbol entry.
- Description:
- Prepares for walking the contents of a symbol table by returning the first entry in the symbol table.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable.
- Returns:
- Pointer to the first entry in the symbol table.
Return the count of symbols in a symbol entry.
- Description:
- Returns the number of symbols currently existing in a symbol table.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable.
- Returns:
- Integer count of the number of entries.
Return the next symbol in a symbol entry.
- Description:
- Continues walking the contents of a symbol table by returning the next entry in the symbol table. A previous call to mprGetFirstSymbol or mprGetNextSymbol is required to supply the value of the last argument.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable. last Symbol table entry returned via mprGetFirstSymbol or mprGetNextSymbol.
- Returns:
- Pointer to the first entry in the symbol table.
Lookup a symbol in the hash table.
- Description:
- Lookup a symbol key and return the value associated with that key.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable. key String key of the symbole entry to delete.
- Returns:
- Value associated with the key when the entry was inserted via mprInsertSymbol.
Lookup a symbol in the hash table and return the hash entry.
- Description:
- Lookup a symbol key and return the hash table descriptor associated with that key.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable. key String key of the symbole entry to delete.
- Returns:
- MprHash table structure for the entry.
Remove a symbol entry from the hash table.
- Description:
- Removes a symbol entry from the symbol table. The entry is looked up via the supplied key.
- Parameters:
-
table Symbol table returned via mprCreateSymbolTable. key String key of the symbole entry to delete.
- Returns:
- Returns zero if successful, otherwise a negative MPR error code is returned.
MprLog
Logging Services.
- API Stability:
- Evolving.
- See Also:
- MprLogHandler, mprError, mprFatalError, mprGetLogHandler, mprLog, mprMemoryError, mprRawLog, mprSetLogHandler, mprSetLogLevel, mprStaticAssert, mprStaticError, mprUserError
- Fields:
-
Log an error message.
- Description:
- Send an error message to the MPR debug logging subsystem. The message will be to the log handler defined by mprSetLogHandler. It is up to the log handler to respond appropriately and log the message.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
Log a fatal error message and exit.
- Description:
- Send a fatal error message to the MPR debug logging subsystem and then exit the application by calling exit(). The message will be to the log handler defined by mprSetLogHandler. It is up to the log handler to respond appropriately and log the message.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
Get the current MPR debug log handler.
- Description:
- Get the log handler defined via mprSetLogHandler.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- A function of the signature MprLogHandler.
Write a message to the diagnostic log file.
- Description:
- Send a message to the MPR logging subsystem.
- Parameters:
-
level Logging level for this message. The level is 0-9 with zero being the most verbose. ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
- Remarks:
- MprLog is highly useful as a debugging aid when integrating or when developing new modules.
Log a memory error message.
- Description:
- Send a memory error message to the MPR debug logging subsystem. The message will be passed to the log handler defined by mprSetLogHandler. It is up to the log handler to respond appropriately to the fatal message, the MPR takes no other action other than logging the message. Typically, a memory message will be logged and the application will be shutdown. The preferred method of operation is to define a memory depletion callback via mprCreate. This will be invoked whenever a memory allocation error occurs.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
Write a raw log message to the diagnostic log file.
- Description:
- Send a raw message to the MPR logging subsystem. Raw messages do not have any application prefix attached to the message and do not append a newline to the message.
- Parameters:
-
level Logging level for this message. The level is 0-9 with zero being the most verbose. ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
- Remarks:
- MprLog is highly useful as a debugging aid when integrating or when developing new modules.
Set an MPR debug log handler.
- Description:
- Defines a callback handler for MPR debug and error log messages. When output is sent to the debug channel, the log handler will be invoked to accept the output message.
- Parameters:
-
ctx Any memory context allocated by the MPR. handler Callback handler. handlerData Callback handler data.
Set the current logging level.
- Description:
- This call defines the maximum level of messages that will be logged. Calls to mprLog specify a message level. If the message level is greater than the defined logging level, the message is ignored.
- Parameters:
-
ctx Any memory context allocated by the MPR. level New logging level. Must be 0-9 inclusive.
- Returns:
- The previous logging level.
- API Stability:
- Evolving.
Output an assertion failed message.
- Description:
- This will emit an assertion failed message to the standard error output. It will bypass the logging system.
- Parameters:
-
loc Source code location string. Use MPR_LOC to define a file name and line number string suitable for this parameter. msg Simple string message to output.
Write a message to the diagnostic log file without allocating any memory.
Useful for log messages from within the memory allocator- Description:
- Send a message to the MPR logging subsystem. This will not allocate any memory while formatting the message. The formatted message string will be truncated in size to MPR_MAX_STRING bytes.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
Display an error message to the user.
- Description:
- Display an error message to the user and then send it to the MPR debug logging subsystem. The message will be passed to the log handler defined by mprSetLogHandler. It is up to the log handler to respond appropriately and display the message to the user.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string. Variable number of arguments to. ... Variable number of arguments for printf data.
MprModule
Loadable Module Service.
- Description:
- The MPR provides services to load and unload shared libraries.
- See Also:
- MprModuleProc, mprCreateModule, mprGetModuleSearchPath, mprLoadModule, mprLookupModule, mprSetModuleSearchPath, mprUnloadModule
- API Stability:
- Evolving.
- Fields:
-
Create a module.
- Description:
- This call will create a module object for a loadable module. This should be invoked by the module itself in its module entry point to register itself with the MPR.
- Parameters:
-
ctx Any memory context allocated by the MPR. name Name of the module. version Version string of the form: Major.Minor.patch. moduleData to associate with this module. start Start function to invoke to start module services. stop Stop function to invoke to stop module services.
- Returns:
- A module object for this module.
Get the module search path.
- Description:
- Get the directory search path used by the MPR when loading dynamic modules. This is a colon separated (or semicolon on Windows) set of directories.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- The module search path. Caller must not free.
Load a module.
- Description:
- Load a module into the MPR. This will load a dynamic shared object (shared library) and call the modules entry point. If the module has already been loaded, it this call will do nothing and will just return the already defined module object.
- Parameters:
-
ctx Any memory context allocated by the MPR. filename Name of the module to load. The module will be searched using the defined module search path (see mprSetModuleSearchPath). The filename may or may not include a platform specific shared library extension such as .dll, .so or .dylib. By omitting the library extension, code can portably load shared libraries. entryPoint Name of function to invoke after loading the module.
- Returns:
- A module object for this module created in the module entry point by calling mprCreateModule.
Lookup a module.
- Description:
- Lookup a module by name and return the module object.
- Parameters:
-
ctx Any memory context allocated by the MPR. name Name of the module specified to mprCreateModule.
- Returns:
- A module object for this module created in the module entry point by calling mprCreateModule.
Set the module search path.
- Description:
- Set the directory search path used by the MPR when loading dynamic modules. This path string must should be a colon separated (or semicolon on Windows) set of directories.
- Parameters:
-
ctx Any memory context allocated by the MPR. searchPath Colon separated set of directories.
- Returns:
- The module search path. Caller must not free.
Unload a module.
- Description:
- Unload a module from the MPR. This will unload a dynamic shared object (shared library). This routine is not fully supported by the MPR and is often fraught with issues. A module must usually be completely inactive with no allocated memory when it is unloaded.
- Parameters:
-
mp Module object returned via mprLookupModule.
MprSocket
Socket Service.
- Description:
- The MPR Socket service provides IPv4 and IPv6 capabilities for both client and server endpoints. Datagrams, Broadcast and point to point services are supported. The APIs can be used in both blocking and non-blocking modes.
The socket service integrates with the MPR worker thread pool and eventing services. Socket connections can be handled by threads from the worker thread pool for scalable, multithreaded applications.
- API Stability:
- Evolving.
- See Also:
- mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
- Fields:
-
Close a socket.
- Description:
- Close a socket. If the graceful option is true, the socket will first wait for written data to drain before doing a graceful close.
- Parameters:
-
sp Socket object returned from mprCreateSocket. graceful Set to true to do a graceful close. Otherwise, an abortive close will be performed.
- See Also:
- MprSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Create a socket.
- Description:
- Create a new socket.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc. ssl An optional SSL context if the socket is to support SSL. Use the MPR_SECURE_CLIENT define to specify that mprCreateSocket should use the default SSL provider.
- Returns:
- A new socket object.
- See Also:
- MprSocket, mprCloseSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Flush a socket.
- Description:
- Flush any buffered data in a socket. Standard sockets do not use buffering and this call will do nothing. SSL sockets do buffer and calling mprFlushSocket will write pending written data.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- A count of bytes actually written. Return a negative MPR error code on errors.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Get the socket blocking mode.
- Description:
- Return the current blocking mode setting.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- True if the socket is in blocking mode. Otherwise false.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Get a socket error code.
- Description:
- This will map a Windows socket error code into a posix error code.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- A posix error code.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Get the socket file descriptor.
- Description:
- Get the file descriptor associated with a socket.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- The integer file descriptor used by the O/S for the socket.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Get the port used by a socket.
- Description:
- Get the TCP/IP port number used by the socket.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- The integer TCP/IP port number used by the socket.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Test if the socket has buffered read data.
- Description:
- Use this function to avoid waiting for incoming I/O if data is already buffered.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- True if the socket has pending read data.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Test if the other end of the socket has been closed.
- Description:
- Determine if the other end of the socket has been closed and the socket is at end-of-file.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- True if the socket is at end-of-file.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Determine if the socket is secure.
- Description:
- Determine if the socket is using SSL to provide enhanced security.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
- Returns:
- True if the socket is using SSL, otherwise zero.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Open a client socket.
- Description:
- Open a client connection.
- Parameters:
-
sp Socket object returned via mprCreateSocket. hostName Host or IP address to connect to. port TCP/IP port number to connect to. flags Socket flags may use the following flags ored together: - MPR_SOCKET_BLOCK - to use blocking I/O. The default is non-blocking.
- MPR_SOCKET_BROADCAST - Use IPv4 broadcast
- MPR_SOCKET_DATAGRAM - Use IPv4 datagrams
- MPR_SOCKET_NOREUSE - Set NOREUSE flag on the socket
- MPR_SOCKET_NODELAY - Set NODELAY on the socket
- MPR_SOCKET_THREAD - Process callbacks on a separate thread.
- Returns:
- Zero if the connection is successful. Otherwise a negative MPR error code.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Open a server socket.
- Description:
- Open a server socket and listen for client connections.
- Parameters:
-
sp Socket object returned via mprCreateSocket. ipAddr IP address to bind to. Set to 0.0.0.0 to bind to all possible addresses on a given port. port TCP/IP port number to connect to. acceptFn Callback function to invoke to accept incoming client connections. data Opaque data reference to pass to the accept function. flags Socket flags may use the following flags ored together: - MPR_SOCKET_BLOCK - to use blocking I/O. The default is non-blocking.
- MPR_SOCKET_BROADCAST - Use IPv4 broadcast
- MPR_SOCKET_DATAGRAM - Use IPv4 datagrams
- MPR_SOCKET_NOREUSE - Set NOREUSE flag on the socket
- MPR_SOCKET_NODELAY - Set NODELAY on the socket
- MPR_SOCKET_THREAD - Process callbacks on a separate thread.
- Returns:
- Zero if the connection is successful. Otherwise a negative MPR error code.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Read from a socket.
- Description:
- Read data from a socket. The read will return with whatever bytes are available. If none and the socket is in blocking mode, it will block untill there is some data available or the socket is disconnected.
- Parameters:
-
sp Socket object returned from mprCreateSocket. buf Pointer to a buffer to hold the read data. size Size of the buffer.
- Returns:
- A count of bytes actually read. Return a negative MPR error code on errors.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Set the socket blocking mode.
- Description:
- Set the blocking mode for a socket. By default a socket is in non-blocking mode where read / write calls will not block.
- Parameters:
-
sp Socket object returned from mprCreateSocket. on Set to zero to put the socket into non-blocking mode. Set to non-zero to enable blocking mode.
- Returns:
- The old blocking mode if successful or a negative MPR error code.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Set the socket callback.
- Description:
- Define a socket callback function to invoke in response to socket I/O events.
- Parameters:
-
sp Socket object returned from mprCreateSocket. fn Callback function. data Data to pass with the callback. mask Bit mask of events of interest. Set to MPR_READABLE and/or MPR_WRITABLE. priority Priority to associate with the event. Priorities are integer values between 0 and 100 inclusive with 50 being a normal priority. (See MPR_NORMAL_PRIORITY).
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Define the events of interest for a socket.
- Description:
- Define an event mask of interest for a socket. The mask is made by oring the MPR_READABLE and MPR_WRITABLE flags as requried.
- Parameters:
-
sp Socket object returned from mprCreateSocket. mask Set to true to do a graceful close. Otherwise, an abortive close will be performed.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Set the socket delay mode.
- Description:
- Set the socket delay behavior (nagle algorithm). By default a socket will partial packet writes a little to try to accumulate data and coalesce TCP/IP packages. Setting the delay mode to false may result in higher performance for interactive applications.
- Parameters:
-
sp Socket object returned from mprCreateSocket. on Set to non-zero to put the socket into no delay mode. Set to zero to enable the nagle algorithm.
- Returns:
- The old delay mode if successful or a negative MPR error code.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprWriteSocket, mprWriteSocketString, mprWriteSocketVector
Write to a socket.
- Description:
- Write a block of data to a socket. If the socket is in non-blocking mode (the default), the write may return having written less than the required bytes.
- Parameters:
-
sp Socket object returned from mprCreateSocket. buf Reference to a block to write to the socket. len Length of data to write. This may be less than the requested write length if the socket is in non-blocking mode. Will return a negative MPR error code on errors.
- Returns:
- A count of bytes actually written. Return a negative MPR error code on errors.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocketString, mprWriteSocketVector
Write to a string to a socket.
- Description:
- Write a string to a socket. If the socket is in non-blocking mode (the default), the write may return having written less than the required bytes.
- Parameters:
-
sp Socket object returned from mprCreateSocket. str Null terminated string to write.
- Returns:
- A count of bytes actually written. Return a negative MPR error code on errors.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketVector
Write a vector to a socket.
- Description:
- Do scatter/gather I/O by writing a vector of buffers to a socket.
- Parameters:
-
sp Socket object returned from mprCreateSocket. iovec Vector of data to write before the file contents. count Count of entries in beforeVect.
- Returns:
- A count of bytes actually written. Return a negative MPR error code on errors.
- See Also:
- MprSocket, mprCloseSocket, mprCreateSocket, mprFlushSocket, mprFree, mprGetSocketBlockingMode, mprGetSocketBlockingMode, mprGetSocketError, mprGetSocketFd, mprGetSocketPort, mprIsSocketEof, mprIsSocketSecure, mprOpenClientSocket, mprOpenServerSocket, mprParseIp, mprReadSocket, mprSetSocketCallback, mprSetSocketEof, mprSetSocketEventMask, mprSetSocketNoDelay, mprWriteSocket, mprWriteSocketString
MprSynch
Multithreaded Synchronization Services.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateCond, mprCreateSpinLock, mprFree, mprFree, mprGlobalLock, mprGlobalUnlock, mprLock, mprSignalCond, mprTryLock, mprUnlock, mprWaitForCond
- API Stability:
- Evolving.
- Fields:
-
Create a condition lock variable.
- Description:
- This call creates a condition variable object that can be used in mprWaitForCond and mprSignalCond calls. Use mprFree to destroy the condition variable.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateSpinLock, mprFree, mprFree, mprGlobalLock, mprGlobalUnlock, mprLock, mprSignalCond, mprTryLock, mprUnlock, mprWaitForCond
Create a Mutex lock object.
- Description:
- This call creates a Mutex lock object that can be used in mprLock, mprTryLock and mprUnlock calls. Use mprFree to destroy the lock.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
Create a spin lock lock object.
- Description:
- This call creates a spinlock object that can be used in mprSpinLock, and mprSpinUnlock calls. Spin locks using MprSpin are much faster than MprMutex based locks on some systems. Use mprFree to destroy the lock.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateCond, mprFree, mprFree, mprGlobalLock, mprGlobalUnlock, mprLock, mprSignalCond, mprTryLock, mprUnlock, mprWaitForCond
Globally lock the application.
- Description:
- This call asserts the application global lock so that other threads calling mprGlobalLock will block until the current thread calls mprGlobalUnlock.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateCond, mprCreateSpinLock, mprFree, mprFree, mprGlobalUnlock, mprLock, mprSignalCond, mprTryLock, mprUnlock, mprWaitForCond
Unlock the global mutex.
- Description:
- This call unlocks the global mutex previously locked via mprGlobalLock.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateCond, mprCreateSpinLock, mprFree, mprFree, mprGlobalLock, mprLock, mprSignalCond, mprTryLock, mprUnlock, mprWaitForCond
Initialize a statically allocated Mutex lock object.
- Description:
- This call initialized a Mutex lock object without allocation. The object can then be used used in mprLock, mprTryLock and mprUnlock calls.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. mutex Reference to an MprMutex structure to initialize.
- Returns:
- A reference to the supplied mutex. Returns null on errors.
Initialize a statically allocated spinlock object.
- Description:
- This call initialized a spinlock lock object without allocation. The object can then be used used in mprSpinLock and mprSpinUnlock calls.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. lock Reference to a static MprSpin object.
- Returns:
- A reference to the MprSpin object. Returns null on errors.
Lock access.
- Description:
- This call asserts a lock on the given lock mutex so that other threads calling mprLock will block until the current thread calls mprUnlock.
Signal a condition lock variable.
- Description:
- Signal a condition variable and set it to the triggered status. Existing or future callers of mprWaitForCond will be awakened.
- Parameters:
-
cond Condition variable object created via mprCreateCond.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateCond, mprCreateSpinLock, mprFree, mprFree, mprGlobalLock, mprGlobalUnlock, mprLock, mprTryLock, mprUnlock, mprWaitForCond
Lock a spinlock.
- Description:
- This call asserts a lock on the given spinlock so that other threads calling mprSpinLock will block until the curren thread calls mprSpinUnlock.
Unlock a spinlock.
- Description:
- This call unlocks a spinlock previously locked via mprSpinLock or mprTrySpinLock.
Attempt to lock access.
- Description:
- This call attempts to assert a lock on the given lock mutex so that other threads calling mprLock or mprTryLock will block until the current thread calls mprUnlock.
- Returns:
- Returns zero if the successful in locking the mutex. Returns a negative MPR error code if unsuccessful.
Attempt to lock access on a spin lock.
- Description:
- This call attempts to assert a lock on the given spin lock so that other threads calling mprSpinLock or mprTrySpinLock will block until the current thread calls mprSpinUnlock.
- Returns:
- Returns zero if the successful in locking the spinlock. Returns a negative MPR error code if unsuccessful.
Unlock a mutex.
- Description:
- This call unlocks a mutex previously locked via mprLock or mprTryLock.
Wait for a condition lock variable.
- Description:
- Wait for a condition lock variable to be signaled. If the condition is signaled before the timeout expires this call will reset the condition variable and return. This way, it automatically resets the variable for future waiters.
- Parameters:
-
cond Condition variable object created via mprCreateCond. timeout Time in milliseconds to wait for the condition variable to be signaled.
- Returns:
- Zero if the event was signalled. Returns < 0 for a timeout.
- See Also:
- MprCond, MprMutex, MprSpin, mprCreateCond, mprCreateSpinLock, mprFree, mprFree, mprGlobalLock, mprGlobalUnlock, mprLock, mprSignalCond, mprTryLock, mprUnlock
Wait for a condition lock variable and pump events while waiting.
- Description:
- Wait for a condition lock variable to be signaled. If the condition is signaled before the timeout expires this call will reset the condition variable and return. This way, it automatically resets the variable for future waiters.
- Parameters:
-
cond Condition variable object created via mprCreateCond. timeout Time in milliseconds to wait for the condition variable to be signaled.
- Returns:
- Zero if the event was signalled. Returns < 0 for a timeout.
MprThread
Thread Service.
- Description:
- The MPR provides a cross-platform thread abstraction above O/S native threads. It supports arbitrary thread creation, thread priorities, thread management and thread local storage. By using these thread primitives with the locking and synchronization primitives offered by MprMutex, MprSpin and MprCond - you can create cross platform multi-threaded applications.
- API Stability:
- Evolving.
- See Also:
- mprCreateThread, mprGetCurrentOsThread, mprGetCurrentThread, mprGetThreadName, mprGetThreadPriority, mprSetThreadPriority, mprSetThreadPriority, mprStartThread
- Fields:
-
Create a new thread.
- Description:
- MPR threads are usually real O/S threads and can be used with the various locking services (MprMutex, MprCond, MprSpin) to enable scalable multithreaded applications.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. name Unique name to give the thread. proc Entry point function for the thread. mprStartThread will invoke this function to start the thread. data Thread private data stored in MprThread.data. priority Priority to associate with the thread. Mpr thread priorities are are integer values between 0 and 100 inclusive with 50 being a normal priority. The MPR maps these priorities in a linear fashion onto native O/S priorites. Useful constants are: - MPR_LOW_PRIORITY
- MPR_NORMAL_PRIORITY
- MPR_HIGH_PRIORITY
stackSize Stack size to use for the thread. On VM based systems, increasing this value, does not necessarily incurr a real memory (working-set) increase. Set to zero for a default stack size.
- Returns:
- A MprThread object.
Get the O/S thread.
- Description:
- Get the O/S thread ID for the currently executing thread.
- Returns:
- Returns a platform specific O/S thread ID. On Unix, this is a pthread reference. On other systems it is a thread integer value.
Get the currently executing thread.
- Description:
- Get the thread object for the currently executing O/S thread.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- Returns a thread object representing the current O/S thread.
Get the thread name.
- Description:
- MPR threads are usually real O/S threads and can be used with the various locking services (MprMutex, MprCond, MprSpin) to enable scalable multithreaded applications.
- Parameters:
-
thread Thread object returned from mprCreateThread.
- Returns:
- Returns a string name for the thread. Caller must not free.
Get the thread priroity.
- Description:
- Get the current priority for the specified thread.
- Parameters:
-
thread Thread object returned by mprCreateThread.
- Returns:
- An integer MPR thread priority between 0 and 100 inclusive.
Set the thread priroity for the current thread.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Description:
- Set the current priority for the specified thread.
- Parameters:
-
priority Priority to associate with the thread. Mpr thread priorities are are integer values between 0 and 100 inclusive with 50 being a normal priority. The MPR maps these priorities in a linear fashion onto native O/S priorites. Useful constants are: - MPR_LOW_PRIORITY
- MPR_NORMAL_PRIORITY
- MPR_HIGH_PRIORITY
Set the thread priroity.
- Description:
- Set the current priority for the specified thread.
- Parameters:
-
thread Thread object returned by mprCreateThread. priority Priority to associate with the thread. Mpr thread priorities are are integer values between 0 and 100 inclusive with 50 being a normal priority. The MPR maps these priorities in a linear fashion onto native O/S priorites. Useful constants are: - MPR_LOW_PRIORITY
- MPR_NORMAL_PRIORITY
- MPR_HIGH_PRIORITY
Start a thread.
- Description:
- Start a thread previously created via mprCreateThread. The thread will begin at the entry function defined in mprCreateThread.
- Parameters:
-
thread Thread object returned from mprCreateThread.
- Returns:
- Returns zero if successful, otherwise a negative MPR error code.
MprWaitHandler
Wait Handler Service.
- Description:
- Wait handlers provide callbacks for when I/O events occur. They provide a wait to service many I/O file descriptors without requiring a thread per descriptor.
- See Also:
- MprEvent, mprCreateEvent, mprDisableWaitEvents, mprEnableWaitEvents, mprRecallWaitHandler, mprServiceEvents, mprSetWaitCallback, mprSetWaitEvents
- Fields:
-
Create a wait handler.
- Description:
- Create a wait handler that will be invoked when I/O of interest occurs on the specified file handle The wait handler is registered with the MPR event I/O mechanism.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc. fd File descriptor. mask Mask of events of interest. This is made by oring MPR_READABLE and MPR_WRITABLE. proc Callback function to invoke when an I/O event of interest has occurred. data Data item to pass to the callback. priority MPR priority to associate with the callback. This is only used if the MPR_WAIT_THREAD is specified in the flags and the MPR is build multithreaded. flags Flags may be set to MPR_WAIT_THREAD if the callback function should be invoked using a thread from the worker thread pool.
- Returns:
- A new wait handler registered with the MPR event mechanism.
Disable wait events.
- Description:
- Disable wait events for a given file descriptor.
- Parameters:
-
wp Wait handler created via mprCreateWaitHandler.
- See Also:
- MprEvent, MprWaitHandler, mprCreateEvent, mprEnableWaitEvents, mprRecallWaitHandler, mprServiceEvents, mprSetWaitCallback, mprSetWaitEvents
Enable wait events.
- Description:
- Enable wait events for a given file descriptor.
- Parameters:
-
wp Wait handler created via mprCreateWaitHandler.
- See Also:
- MprEvent, MprWaitHandler, mprCreateEvent, mprDisableWaitEvents, mprRecallWaitHandler, mprServiceEvents, mprSetWaitCallback, mprSetWaitEvents
Recall a wait handler.
- Description:
- Signal that a wait handler should be recalled at the earliest opportunity. This is useful when a protocol stack has buffered data that must be processed regardless of whether more I/O occurs.
- Parameters:
-
wp Wait handler created via mprCreateWaitHandler.
- See Also:
- MprEvent, MprWaitHandler, mprCreateEvent, mprDisableWaitEvents, mprEnableWaitEvents, mprServiceEvents, mprSetWaitCallback, mprSetWaitEvents
Define the wait handler callback.
- Description:
- This updates the callback function for the wait handler. Callback functions are originally specified via mprCreateWaitHandler.
- Parameters:
-
wp Wait handler created via mprCreateWaitHandler. proc Callback function to invoke when an I/O event of interest has occurred. mask Mask of MPR_READABLE and MPR_WRITABLE.
- See Also:
- MprEvent, MprWaitHandler, mprCreateEvent, mprDisableWaitEvents, mprEnableWaitEvents, mprRecallWaitHandler, mprServiceEvents, mprSetWaitEvents
Define the events of interest for a wait handler.
- Description:
- Define the events of interest for a wait handler. The mask describes whether readable or writable events should be signalled to the wait handler. Disconnection events are passed via read events.
- Parameters:
-
wp Wait handler created via mprCreateWaitHandler. desiredMask Mask of desirable events (MPR_READABLE | MPR_WRITABLE). disableMask Mask to enable or disable events. Set to -1 to enable events, 0 to disable.
- See Also:
- MprEvent, MprWaitHandler, mprCreateEvent, mprDisableWaitEvents, mprEnableWaitEvents, mprRecallWaitHandler, mprServiceEvents, mprSetWaitCallback
MprWorkerService
Worker Thread Service.
- Description:
- The MPR provides a worker thread pool for rapid starting and assignment of threads to tasks.
- API Stability:
- Evolving.
- See Also:
- mprSetMaxWorkers, mprSetMinWorkers
- Fields:
-
Get the count of available worker threads Return the count of free threads in the worker thread pool.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc.
- Returns:
- An integer count of worker threads.
- See Also:
- MprWorkerService, mprSetMaxWorkers, mprSetMinWorkers
Get the maximum count of worker pool threads Get the maximum limit of worker pool threads.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc.
- Returns:
- The maximum count of worker pool threads.
- See Also:
- MprWorkerService, mprSetMaxWorkers, mprSetMinWorkers
Set the maximum count of worker threads Set the maximum number of worker pool threads for the MPR.
If this number if less than the current number of threads, excess threads will be gracefully pruned as they exit- Parameters:
-
ctx Any memory allocation context created by MprAlloc. count Maximum limit of threads to define.
- See Also:
- MprWorkerService, mprSetMinWorkers
Set the minimum count of worker threads Set the count of threads the worker pool will have.
This will cause the worker pool to pre-create at least this many threads- Parameters:
-
ctx Any memory allocation context created by MprAlloc. count Minimum count of threads to use.
- See Also:
- MprWorkerService, mprSetMaxWorkers
Functions
Format a string into an allocated buffer.
- Description:
- This call will dynamically allocate a buffer up to the specified maximum size and will format the supplied arguments into the buffer. A trailing null will always be appended. The call returns the size of the allocated string excluding the null.
- Parameters:
-
ctx Any memory context allocated by the MPR. maxSize Maximum size to allocate for the buffer including the trailing null. fmt Printf style format string.
- Returns:
- The number of characters in the string.
Convert a string to an integer.
- Description:
- This call converts the supplied string to an integer using the specified radix (base).
- Parameters:
-
str Pointer to the string to parse. radix Base to use when parsing the string.
- Returns:
- The integer equivalent value of the string.
Configure SSL based on the parsed MprSsl configuration.
- Parameters:
-
ssl MprSsl configuration.
Create a new event dispatcher.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- Returns:
- A Dispatcher object that can manage events and be used with mprCreateEvent.
Deocde buffer using base-46 encoding.
- Parameters:
-
buffer Reference to a buffer containing that data to decode. bufsize size of the buffer in bytes. str String to decode.
- Returns:
- Zero if successful, otherwise returns MPR_ERR_WONT_FIT if the buffer is too small.
Dedicate a worker thread to a current real thread.
This implements thread affinity and is required on some platforms where some APIs (waitpid on uClibc) cannot be called on a different thread- Parameters:
-
worker Worker object. worker Worker thread reference.
Dedicate a worker thread to a wait handler.
This implements thread affinity and is required on some platforms where some APIs (waitpid on uClibc) cannot be called on a different thread- Parameters:
-
wp Wait handler created via mprCreateWaitHandler. worker Worker thread reference.
Disable socket events for a socket callback.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
Disconnect a socket by closing its underlying file descriptor.
This is used to prevent further I/O wait events while still preserving the socket object- Parameters:
-
sp Socket object.
Disconnect a wait handler from its underlying file descriptor.
This is used to prevent further I/O wait events while still preserving the wait handler- Parameters:
-
wp Wait handler object.
Convert a double to ascii.
- Parameters:
-
ctx Any memory context allocated by the MPR. value Value to convert. mode. Modes are: 0 Shortest string, 1 Like 0, but with Steele & White stopping rule, 2 Return ndigits of result, 3 Number of digits applies after the decimal point. ndigits Number of digits to render. flags Format flags.
Enable socket events for a socket callback.
- Parameters:
-
sp Socket object returned from mprCreateSocket.
Encode buffer using base-46 encoding.
- Parameters:
-
buffer Reference to a buffer that will contain the encoded data. bufsize size of the buffer in bytes. str String to encode.
- Returns:
- Zero if successful, otherwise returns MPR_ERR_WONT_FIT if the buffer is too small.
Print a formatted message to a file descriptor.
- Description:
- This is a replacement for fprintf as part of the safe string MPR library. It minimizes memory use and uses a file descriptor instead of a File pointer.
- Parameters:
-
file MprFile object returned via mprOpen. fmt Printf style format string.
- Returns:
- The number of bytes written.
Free all the children blocks allocated of a block.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
Return the current allocation memory statistics block.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- Returns:
- A reference to the allocation memory statistics. Do not modify its contents.
Get the application name defined via mprSetAppName.
- Returns:
- The one-word lower case application name defined via mprSetAppName.
Return the current working directory.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- Returns an allocated string with the current working directory as an absolute path.
Get the elapsed time since a time mark.
Create the time mark with mprGetTime()- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. mark Starting time stamp.
- Returns:
- The time elapsed since the mark was taken.
Get the current O/S virtual page size.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- Returns:
- The page size in bytes.
Return a file object for the Stderr I/O channel.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- A file object.
Return a file object for the Stdin I/O channel.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- A file object.
Return a file object for the Stdout I/O channel.
- Parameters:
-
ctx Any memory context allocated by the MPR.
- Returns:
- A file object.
Return the amount of memory currently used by the application.
This only reports heap memory- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- Returns:
- The amount of heap memory used by the application in bytes.
Get the next word token.
- Description:
- Split a string into word tokens using the supplied separator.
- Parameters:
-
buf Buffer to use to hold the word token. bufsize Size of the buffer. str Input string to tokenize. Note this cannot be a const string. It will be written. delim String of separator characters to use when tokenizing. tok Pointer to a word to hold a pointer to the next token in the original string.
- Returns:
- The number of bytes in the allocated block.
Invoke the wait handler callback.
- Parameters:
-
wp Wait handler created via mprCreateWaitHandler.
Test is a pointer is a valid memory context.
This is used to test if a block has been dynamically allocated- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
Convert an integer to a string.
- Description:
- This call converts the supplied integer into a string formatted into the supplied buffer.
- Parameters:
-
buf Pointer to the buffer that will hold the string. size Size of the buffer. value Integer value to convert. radix The base radix to use when encoding the number.
- Returns:
- The number of characters in the string.
Load the SSL module.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc. lazy Set to true to delay initialization until SSL is actually used.
Get the mime type for an extension.
This call will return the mime type from a limited internal set of mime types for the given path or extension- Parameters:
-
ctx Any memory allocation context created by MprAlloc. ext Path or extension to examine.
- Returns:
- Mime type. This is a static string. Caller must not free.
Memory virtual memory into the applications address space.
- Parameters:
-
size of virtual memory to map. This size will be rounded up to the nearest page boundary. mode Mask set to MPR_MAP_READ | MPR_MAP_WRITE.
Free (unpin) a mapped section of virtual memory.
- Parameters:
-
ptr Virtual address to free. Should be page aligned. size Size of memory to free in bytes.
Compare two byte strings.
- Description:
- Safely compare two byte strings. This is a safe replacement for memcmp.
- Parameters:
-
b1 Pointer to the first byte string. b1Len Length of the first byte string. b2 Pointer to the second byte string. b2Len Length of the second byte string.
- Returns:
- Returns zero if the byte strings are identical. Otherwise returns -1 if the first string is less than the second. Returns 1 if the first is greater than the first.
Safe copy for a block of data.
- Description:
- Safely copy a block of data into an existing memory block. The call ensures the destination block is not overflowed and returns the size of the block actually copied. This is similar to memcpy, but is a safer alternative.
- Parameters:
-
dest Pointer to the destination block. destMax Maximum size of the destination block. src Block to copy. nbytes Size of the source block.
- Returns:
- The number of characters in the allocated block.
Test if the request needs a transparent retry to implement authentication or redirection.
If authentication is required, a request must first be tried once to receive some authentication key information that must be resubmitted to gain access- Parameters:
-
http Http object created via mprCreateHttp. url Reference to a string to receive a redirection URL. Set to NULL if not redirection is required.
- Returns:
- True if the request needs to be retried.
Parse an IP address.
This parses a string containing an IP:PORT specification and returns the IP address and port components. Handles ipv4 and ipv6 addresses- Parameters:
-
ctx Any memory allocation context created by MprAlloc. ipSpec An IP:PORT specification. The :PORT is optional. When an ipAddrPort contains an ipv6 port it should be written as aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh:iiii or [aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh:iiii]:port. ipAddr Pointer to receive a dynamically allocated IP string. Caller should free. port Pointer to an integer to receive the port value. defaultPort The default port number to use if the ipSpec does not contain a port.
Formatted print.
This is a secure verion of printf that can handle null args- Description:
- This is a secure replacement for printf. It can handle null arguments without crashes. minimal footprint. The MPR can be build without using any printf routines.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string.
- Returns:
- The number of bytes written.
Print a formatted message to the standard error channel.
- Description:
- This is a secure replacement for fprintf(stderr.
- Parameters:
-
ctx Any memory context allocated by the MPR. fmt Printf style format string.
- Returns:
- The number of bytes written.
Append strings to an existing string and reallocate as required.
- Description:
- Append a list of strings to an existing string. The list of strings is terminated by a null argument. The call returns the size of the allocated block.
- Parameters:
-
ctx Any memory context allocated by the MPR. max Maximum size of the result string. buf Existing string to reallocate. May be null. src Variable list of strings to append. The final string argument must be null.
- Returns:
- An allocated result string. Caller must free.
Release a worker thread.
This releases a worker thread to be assignable to any real thread- Parameters:
-
worker Worker object. worker Worker thread reference.
Release a worker thread.
This releases a worker thread to be assignable to any other wait handler- Parameters:
-
wp Wait handler created via mprCreateWaitHandler. worker Worker thread reference.
Reset a condition variable.
This sets the condition variable to the unsignalled condition- Parameters:
-
cond Condition variable object created via mprCreateCond.
Search for a module on the current module path.
- Parameters:
-
ctx Any memory context allocated by the MPR. module Name of the module to locate. path Pointer to a string that will receive the module path. Caller should free.
- Returns:
- 0 if the module was found and path set to the location of the module.
Set an memory allocation error condition on a memory context.
This will set an allocation error condition on the given context and all its parents. This way, you can test the ultimate parent and detect if any memory allocation errors have occurred- Parameters:
-
ctx Any memory context allocated by the MPR.
Set the application name, title and version.
- Parameters:
-
ctx Any memory context allocated by the MPR. name One word, lower case name for the app. title Pascal case multi-word descriptive name. version Version of the app. Major-Minor-Patch. E.g. 1.2.3.
- Returns:
- Zero if successful. Otherwise a negative MPR error code.
Turn on debug mode.
- Description:
- Debug mode disables timeouts and timers. This makes debugging much easier.
- Parameters:
-
ctx Any memory context allocated by the MPR. on Set to true to enable debugging mode.
- API Stability:
- Evolving.
Set whether transfer chunked encoding will be used on this request.
If enabled, a "Transfer-Encoding: Chunked" will be added to the request headers and all write data will be delimited by chunk specifications- Parameters:
-
http Http object created via mprCreateHttp. enable Set to true to enable transfer chunk encoding.
- Returns:
- The previous chunk enable setting.
Set the maximum number of client sockets that are permissable.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc. max New maximum number of client sockets.
Set an EOF condition on the socket.
- Parameters:
-
sp Socket object returned from mprCreateSocket. eof Set to true to set an EOF condition. Set to false to clear it.
Set the default worker stack size.
- Parameters:
-
ctx Any memory allocation context created by MprAlloc. size Stack size in bytes.
Format a string into a statically allocated buffer.
- Description:
- This call format a string using printf style formatting arguments. A trailing null will always be appended. The call returns the size of the allocated string excluding the null.
- Parameters:
-
buf Pointer to the buffer. maxSize Size of the buffer. fmt Printf style format string.
- Returns:
- The buffer.
Monitory stack usage and check if the stack has grown since last monitoring.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate.
- Returns:
- True if the stack has grown.
Start the Mpr services.
- Parameters:
-
mpr Mpr object created via mprCreateMpr. startEventsThread Set to true to start an events thread.
Print a message to the applications standard output without allocating memory.
- Description:
- This is a secure replacement for printf that will not allocate memory.
- Parameters:
-
ctx Any memory context allocated by the MPR. This is used to locate the standard output channel and not to allocate memory. fmt Printf style format string.
- Returns:
- The number of bytes written.
- Remarks:
- The maximum output is MPR_MAX_STRING - 1.
Print a message to the standard error channel without allocating memory.
- Description:
- This is a secure replacement for fprintf(stderr that will not allocate memory.
- Parameters:
-
ctx Any memory context allocated by the MPR. This is used to locate the standard output channel and not to allocate memory. fmt Printf style format string.
- Returns:
- The number of bytes written.
- Remarks:
- The maximum output is MPR_MAX_STRING - 1.
Reassign a block from its current parent context to a new context.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. This will be the new owning context of the ptr. ptr Pointer to a block to reassign.
Stop the MPR and shutdown all services.
After this call, the MPR cannot be used- Parameters:
-
mpr Mpr object created via mprCreateMpr.
Catenate strings.
- Description:
- Safe replacement for strcat. Catenates a string onto an existing string. This call accepts a variable list of strings to append. The list of strings is terminated by a null argument. The call returns the length of the resulting string. This call is similar to strcat, but it will enforce a maximum size for the resulting string and will ensure it is terminated with a null.
- Parameters:
-
ctx Any memory context allocated by mprAlloc or mprCreate. max Maximum size of the new block. src Variable list of strings to append. The final string argument must be null.
- Returns:
- Returns an allocated string.
Compare strings.
- Description:
- Compare two strings. This is a safe replacement for strcmp. It can handle null args.
- Parameters:
-
str1 First string to compare. str2 Second string to compare.
- Returns:
- Returns zero if the strings are identical. Return -1 if the first string is less than the second. Return 1 if the first string is greater than the second.
Compare strings ignoring case.
- Description:
- Compare two strings ignoring case differences. This call operates similarly to strcmp.
- Parameters:
-
str1 First string to compare. str2 Second string to compare.
- Returns:
- Returns zero if the strings are equivalent, < 0 if s1 sorts lower than s2 in the collating sequence or > 0 if it sorts higher.
Compare strings ignoring case.
- Description:
- Compare two strings ignoring case differences for a given string length. This call operates similarly to strncmp.
- Parameters:
-
str1 First string to compare. str2 Second string to compare. len Length of characters to compare.
- Returns:
- Returns zero if the strings are equivalent, < 0 if s1 sorts lower than s2 in the collating sequence or > 0 if it sorts higher.
Copy a string.
- Description:
- Safe replacement for strcpy. Copy a string and ensure the target string is not overflowed. The call returns the length of the resultant string or an error code if it will not fit into the target string. This is similar to strcpy, but it will enforce a maximum size for the copied string and will ensure it is terminated with a null.
- Parameters:
-
dest Pointer to a pointer that will hold the address of the allocated block. destMax Maximum size of the target string. src String to copy.
- Returns:
- The number of characters in the target string.
Copy characters from a string.
- Description:
- Safe replacement for strncpy. Copy bytes from a string and ensure the target string is not overflowed. The call returns the length of the resultant string or an error code if it will not fit into the target string. This is similar to strcpy, but it will enforce a maximum size for the copied string and will ensure it is terminated with a null.
- Parameters:
-
dest Pointer to a pointer that will hold the address of the allocated block. destMax Maximum size of the target string. src String to copy. count Maximum count of characters to copy.
- Returns:
- The number of characters in the target string.
Return the length of a string.
- Description:
- Safe replacement for strlen. This call returns the length of a string and tests if the length is less than a given maximum.
- Parameters:
-
src String to measure. max Maximum length for the string.
- Returns:
- The length of the string or MPR_ERR_WONT_FIT if the length is greater than max.
Convert a string to lower case.
- Description:
- Convert a string to its lower case equivalent.
- Parameters:
-
str String to convert.
- Returns:
- Returns a pointer to the converted string. Will always equal str.
Find a substring.
- Description:
- Locate the first occurrence of pattern in a string, but do not search more than the given length.
- Parameters:
-
str Pointer to the string to search. pattern String pattern to search for. len Count of characters in the pattern to actually search for.
- Returns:
- The number of characters in the target string.
Tokenize a string.
- Description:
- Split a string into tokens.
- Parameters:
-
str String to tokenize. delim String of characters to use as token separators. last Last token pointer.
- Returns:
- Returns a pointer to the next token.
Trim a string.
- Description:
- Trim leading and trailing characters off a string.
- Parameters:
-
str String to trim. set String of characters to remove.
- Returns:
- Returns a pointer to the trimmed string. May not equal str. If str was dynamically allocated, do not call mprFree on the returned trimmed pointer. You must use str when calling mprFree.
Convert a string to upper case.
- Description:
- Convert a string to its upper case equivalent.
- Parameters:
-
str String to convert.
- Returns:
- Returns a pointer to the converted string. Will always equal str.
Apply wait handler updates.
While a wait handler is in use, wait event updates are buffered. This routine applies such buffered updates- Parameters:
-
wp Wait handler created via mprCreateWaitHandler. wakeup Wake up the service events thread. Typically it is safest to wake up the service events thread if the wait handler event masks have been modified. However, there are some cases where it can be useful to suppress this behavior.
Allocate a buffer of sufficient length to hold the formatted string.
- Description:
- This call will dynamically allocate a buffer up to the specified maximum size and will format the supplied arguments into the buffer. A trailing null will always be appended. The call returns the size of the allocated string excluding the null.
- Parameters:
-
ctx Any memory context allocated by the MPR. maxSize Maximum size to allocate for the buffer including the trailing null. fmt Printf style format string. arg Varargs argument obtained from va_start.
- Returns:
- The number of characters in the string.
Format a string into a statically allocated buffer.
- Description:
- This call format a string using printf style formatting arguments. A trailing null will always be appended. The call returns the size of the allocated string excluding the null.
- Parameters:
-
buf Pointer to the buffer. maxSize Size of the buffer. fmt Printf style format string. args Varargs argument obtained from va_start.
- Returns:
- The buffer;.
Typedefs
Http callback procedure Must not delete the http instance in the callback.
- Parameters:
-
http Http object created via mprCreateHttp. mask Event mask.
Module start/stop point function signature.
- Parameters:
-
mp Module object reference returned from mprCreateModule.
- Returns:
- Zero if successful, otherwise return a negative MPR error code.
Socket connection acceptance callback procedure.
Socket I/O callback procedure.
Proc returns non-zero if the socket has been deletedWorker thread callback signature.
- Parameters:
-
data worker callback data. Set via mprStartWorker or mprActivateWorker. worker Reference to the worker thread object.
Buffer refill callback function.
- Description:
- Function to call when the buffer is depleted and needs more data.
- Parameters:
-
buf Instance of an MprBuf. arg Data argument supplied to mprSetBufRefillProc.
- Returns:
- The callback should return 0 if successful, otherwise a negative error code.
- See Also:
- MprBuf, mprAdjustBufEnd, mprAdjustBufStart, mprCreateBuf, mprFlushBuf, mprFree, mprGetBlockFromBuf, mprGetBufEnd, mprGetBufLength, mprGetBufOrigin, mprGetBufRefillProc, mprGetBufSize, mprGetBufSpace, mprGetCharFromBuf, mprGrowBuf, mprInsertCharToBuf, mprLookAtLastCharInBuf, mprLookAtNextCharInBuf, mprPutBlockToBuf, mprPutCharToBuf, mprPutFmtToBuf, mprPutIntToBuf, mprPutStringToBuf, mprRefillBuf, mprResetBufIfEmpty, mprSetBufMax, mprSetBufRefillProc, mprSetBufSize, mprStealBuf
Mpr time structure.
- Description:
- MprTime is the cross platform time abstraction structure. Time is stored as milliseconds since the epoch: 00:00:00 UTC Jan 1 1970. MprTime is typically a 64 bit quantity.
Log handler callback type.
- Description:
- Callback prototype for the log handler. Used by mprSetLogHandler to define a message logging handler to process log and error messages.
- Parameters:
-
file Source filename. Derived by using __FILE__. line Source line number. Derived by using __LINE__. flags Error flags. level Message logging level. Levels are 0-9 with zero being the most verbose. msg Message being logged.
Loadable module entry point signature.
- Description:
- Loadable modules can have an entry point that is invoked automatically when a module is loaded.
- Parameters:
-
ctx Any memory context allocated by the MPR. path Actual path to the module.
- Returns:
- A new MprModule structure for the module. Return NULL if the module can't be initialized.
Memory Allocation Block Header.
- Fields:
-
Condition variable for single and multi-thread synchronization.
- Fields:
-
pthread_cond_t cv Unix pthreads condition variable. struct MprMutex * mutex Thread synchronization mutex. int triggered Value of the condition.
Directory entry description.
- Description:
- The MprGetDirList will create a list of directory entries.
- Fields:
-
bool isDir True if the file is a directory. bool isLink True if the file symbolic link. MprTime lastModified Time the file was last modified. char * name Name of the file. MprOffset size Size of the file.
File system service.
- Description:
- The MPR provides a file system abstraction to support non-disk based file access such as flash or other ROM based file systems. The MprFileSystem structure defines a virtual file system interface that will be invoked by the various MPR file routines.
- Fields:
-
MprAccessFileProc accessPath Virtual access file routine. bool caseSensitive Path comparisons are case sensitive. MprCloseFileProc closeFile Virtual close file routine. char * cygdrive Cygwin drive root. MprDeleteFileProc deletePath Virtual delete file routine. MprGetPathInfoProc getPathInfo Virtual get file information routine. MprGetPathLinkProc getPathLink Virtual get the symbolic link target. bool hasDriveSpecs Paths can have drive specifications. MprMakeDirProc makeDir Virtual make link routine. MprMakeLinkProc makeLink Virtual make directory routine. char * newline Newline for text files. MprOpenFileProc openFile Virtual open file routine. MprReadFileProc readFile Virtual read file routine. cchar * root Root file path. MprSeekFileProc seekFile Virtual seek file routine. char * separators Filename path separators. First separator is the preferred separator. MprSetBufferedProc setBuffered Virtual set buffered I/O routine. struct MprFile * stdError Standard error file. struct MprFile * stdInput Standard input file. struct MprFile * stdOutput Standard output file. MprWriteFileProc writeFile Virtual write file routine.
Hash table control structure.
- Fields:
-
MprHash ** buckets Hash collision bucket table. int count Number of symbols in the table. int hashSize Size of the buckets array.
HTTP Per-request structure.
- Fields:
-
char * bodyData Form post data. int bodyLen Length of bodyData. int chunked Enable chunked transfers. Set to -1 if not yet defined. int flags Request control flags. char * formData Form post data. int formLen Length of formData. MprHashTable * headers Headers keyword values. struct MprHttp * http Reference to Http service object. char * method Request method GET, HEAD, POST, DELETE, OPTIONS, PUT, TRACE. MprBuf * outBuf Request output buffer. int sentCredentials Credentials sent with request. MprUri * uri Request uri.
HTTP Per-response structure.
- Fields:
-
char * authAlgorithm Authentication algorithm. char * authStale Stale handshake value. MprBuf * chunkBuf Holding buffer for the current chunk. int chunkRemaining Remaining content data to read in this chunk. int code Http response status code. int contentLength Content length header. int contentRemaining Remaining content data to read. MprBuf * dataBuf Current response data buffer. int flags Response control flags. MprBuf * headerBuf Header buffer. MprHashTable * headers Headers keyword values. struct MprHttp * http Reference to Http service object. int length Actual length of content received. char * location Redirect location. char * message Http response status message. char * protocol Response protocol "HTTP/1.0" or "HTTP/1.1".
Key value pairs for use with MprList or MprHash.
- Fields:
-
char * key Key string. char * value Associated value for the key.
Multithreading lock control structure.
- Description:
- MprMutex is used for multithread locking in multithreaded applications.
- Fields:
-
CRITICAL_SECTION cs Internal mutex critical section.
Multithreading spin lock control structure.
- Description:
- MprSpin is used for multithread locking in multithreaded applications.
- Fields:
-
CRITICAL_SECTION cs Internal mutex critical section.
Safe String Module.
- Description:
- The MPR provides a suite of safe string manipulation routines to help prevent buffer overflows and other potential security traps.
- Fields:
-
Thread local data storage.
- Fields:
-
pthread_key_t key Data key.