X_IPC_RETURN_STATUS_TYPE x_ipc_writeNBytes(int sd, char *buf, int32 nbytes) { int32 amountWritten = 0; BOOLEAN *pipeBrokenPtr; LOCK_IO_MUTEX; LOCK_M_MUTEX; pipeBrokenPtr = &GET_M_GLOBAL(pipeBroken); UNLOCK_M_MUTEX; while (nbytes > 0) { *pipeBrokenPtr = FALSE; #ifndef OS2 errno = 0; #endif #ifdef _WINSOCK_ SAFE_IO(amountWritten, send(sd, buf, nbytes,0)); #else SAFE_IO(amountWritten, write(sd, buf, nbytes)); #endif if (*pipeBrokenPtr || (errno == EPIPE)) { X_IPC_MOD_WARNING( "\nWARNING: pipe broken!\n"); UNLOCK_IO_MUTEX; return StatError; } else if (amountWritten < 0) { #if defined(VXWORKS) || defined(THINK_C) || defined(macintosh) UNLOCK_IO_MUTEX; return StatError; #else #ifdef _WINSOCK_ if (WSAGetLastError() == WSAEWOULDBLOCK) #else if (errno == EWOULDBLOCK) #endif { X_IPC_MOD_WARNING( "\nWARNING: x_ipc_writeNBytes: EWOULDBLOCK: trying again!\n"); PAUSE_MIN_DELAY(); } else { UNLOCK_IO_MUTEX; return StatError; } #endif } else { nbytes -= amountWritten; buf += amountWritten; } } UNLOCK_IO_MUTEX; return StatOK; }
void x_ipc_hashTableStats(HASH_TABLE_PTR hashTable) { HASH_ELEM_PTR elem; int32 i, num=0, max=0, full=0, length; if (hashTable) { for (i=0;i < hashTable->size; i++) { elem = hashTable->table[i]; if (elem) { full++; length = 0; while (elem) { num++; length++; elem = elem->next; } if (length > max) max = length; } } X_IPC_MOD_WARNING2("x_ipc_hashTableStats: Has %d elements in %d slots\n", num, full); X_IPC_MOD_WARNING2(" Out of %d slots (%.0f percent full)\n", hashTable->size, 100*((double)full/hashTable->size)); X_IPC_MOD_WARNING2(" Average list is %.1f; maximum is %d\n", (double)num/full, max); } else { X_IPC_MOD_WARNING("x_ipc_hashTableStats: No Hash Table\n"); } }
void x_ipc_listFree(LIST_PTR *list) { LIST_ELEM_PTR tmpA, tmpB; if (!(*list)) return; LOCK_LIST_MUTEX; if ((*list)->freeList) { X_IPC_MOD_WARNING( "\nlistFree: OP IGNORED WARNING: list already on free list.\n"); UNLOCK_LIST_MUTEX; return; } tmpA = (*list)->first; while (tmpA) { tmpB = tmpA; tmpA = tmpA->next; x_ipc_listFreeCell(tmpB); } x_ipc_listFreeTop((*list)); *list = NULL; UNLOCK_LIST_MUTEX; }
X_IPC_REF_PTR x_ipcReserveModResource(const char *modName, const char *resName) { int32 refId; MSG_PTR msg; X_IPC_REF_PTR ref; ADD_HND_FORM_TYPE addForm; addForm.hndName = modName; addForm.resName = resName; refId = 0; if (x_ipcQuery(X_IPC_RESERVE_MOD_RESOURCE_QUERY, (void *)&addForm, (void *)&refId) != Success) return NULL; if (refId < 0) { X_IPC_MOD_WARNING( "\nWARNING: Ignoring reservation request.\n"); X_IPC_MOD_WARNING2( "%s of module %s is already reserved by this module.\n", resName, modName); ref = CREATE_NULL_REF(); } else { msg = x_ipc_msgFind(X_IPC_RESERVE_MOD_RESOURCE_QUERY); if (msg == NULL) return NULL; ref = x_ipcRefCreate(msg, X_IPC_RESERVE_MOD_RESOURCE_QUERY, refId); } return ref; }
X_IPC_REF_PTR x_ipcReserveResource(const char *resName) { int32 refId; MSG_PTR msg; X_IPC_REF_PTR ref; refId = 0; if (x_ipcQuery(X_IPC_RESERVE_RESOURCE_QUERY, (void *)&resName, (void *)&refId) != Success) return NULL; if (refId < 0) { X_IPC_MOD_WARNING( "\nWARNING: Ignoring reservation request.\n"); X_IPC_MOD_WARNING1( "%s is already reserved by this module.\n", resName); ref = CREATE_NULL_REF(); } else { msg = x_ipc_msgFind(X_IPC_RESERVE_RESOURCE_QUERY); if (msg == NULL) return NULL; ref = x_ipcRefCreate(msg, X_IPC_RESERVE_RESOURCE_QUERY, refId); } return ref; }
static void ParserError(TokenPtr bad_token, Format_Parse_Ptr parser, char *expecting) { int i; X_IPC_MOD_WARNING2( "Format Parsing Error: Expected %s.\n%s\n", expecting, parser->ParseString); for (i=0; i<bad_token->Loc; i++) X_IPC_MOD_WARNING( " "); /* X_IPC_MOD_ERROR("^\n");*/ }
void x_ipc_idTablePrintInfo(ID_TABLE_PTR table) { if (table) { X_IPC_MOD_WARNING1( "idTable: %s\n", table->name); X_IPC_MOD_WARNING1( "free : %d\n", table->freeTotal); X_IPC_MOD_WARNING1( "size : %d\n", table->currentSize); X_IPC_MOD_WARNING1( "incSize: %d\n", table->incSize); } else X_IPC_MOD_WARNING( "x_ipc_idTablePrintInfo: NULL Table\n"); }
static void centralFreeMemory(u_int32 amount) { #ifdef UNUSED_PRAGMA #pragma unused(amount) #endif /* Try to free up amount of memory. Really want to free more. */ /* Try by deleting stuff from the pending queues. */ /* The problem is that this can consume memory. */ X_IPC_MOD_WARNING("Warning MEMORY EXHAUSTED, purging queues !!!!\n"); purgeResoucePending(); return; }
static void pipeClosedHnd(int s) #endif { #ifdef UNUSED_PRAGMA #pragma unused(s) #endif GET_M_GLOBAL(pipeBroken) = TRUE; X_IPC_MOD_WARNING("Pipe Broke \n"); #ifdef linux /* According to the man page for "signal", the Linux version resets the handler to its default value each time the signal is raised. */ signal(SIGPIPE, pipeClosedHnd); #endif }
static X_IPC_RETURN_STATUS_TYPE x_ipc_writeNBuffers(int sd, struct iovec *vec, int32 amount) { int32 amountWritten = 0; int32 numBuffers=0; int32 amountToWrite=0; int32 i, start=0; BOOLEAN *pipeBrokenPtr; for (i=0; (vec[i].iov_base != NULL); i++) { numBuffers++; amountToWrite += vec[i].iov_len; } if (amountToWrite != amount) { X_IPC_MOD_ERROR("Internal Error: Amounts incorrect in msg send.\n"); return StatError; } LOCK_IO_MUTEX; LOCK_M_MUTEX; pipeBrokenPtr = &GET_M_GLOBAL(pipeBroken); UNLOCK_M_MUTEX; while (amountToWrite > 0) { *pipeBrokenPtr = FALSE; #ifndef OS2 errno = 0; #endif SAFE_IO(amountWritten, writev(sd, &vec[start], numBuffers)); if (*pipeBrokenPtr || (errno == EPIPE)) { X_IPC_MOD_WARNING( "\nWARNING: pipe broken!\n"); x_ipcFree((char *)vec); UNLOCK_IO_MUTEX; return StatError; } else if (amountWritten < 0) { #if defined(VXWORKS) || defined(THINK_C) || defined(macintosh) x_ipcFree((char *)vec); UNLOCK_IO_MUTEX; return StatError; #else #ifdef _WINSOCK_ if (WSAGetLastError() == WSAEWOULDBLOCK) #else if (errno == EWOULDBLOCK) #endif { X_IPC_MOD_WARNING( "\nWARNING: x_ipc_writeNBytes: EWOULDBLOCK: trying again!\n"); PAUSE_MIN_DELAY(); } else { x_ipcFree((char *)vec); UNLOCK_IO_MUTEX; return StatError; } #endif } else { amountToWrite -= amountWritten; if (amountToWrite > 0) { while (amountWritten > 0) { if (vec[start].iov_len <= amountWritten) { amountWritten -= vec[start].iov_len; start++; numBuffers--; } else if (vec[start].iov_len > amountWritten) { vec[start].iov_len -= amountWritten; #ifndef _SGI_SOURCE vec[start].iov_base += amountWritten; #else vec[start].iov_base = (caddr_t)((int32)vec[start].iov_base + amountWritten); #endif amountWritten = 0; } } } } } UNLOCK_IO_MUTEX; x_ipcFree((char *)vec); return StatOK; }
void recvMessage(DISPATCH_PTR dispatch, X_IPC_MSG_CLASS_TYPE msg_class, void *classData) { #ifdef UNUSED_PRAGMA #pragma unused(classData) #endif if (GET_S_GLOBAL(x_ipcDebugGlobal)) { x_ipc_idTablePrintInfo(GET_S_GLOBAL(dispatchTable)); X_IPC_MOD_WARNING("\n"); x_ipcStats(stderr); } switch(msg_class) { case QueryClass: case InformClass: tapWhenSent(dispatch); processActiveMessage(dispatch); break; case ReplyClass: recvReplyMessage(dispatch); break; #ifndef NMP_IPC case GoalClass: case PointMonitorClass: case DemonMonitorClass: case PollingMonitorClass: case ExceptionClass: case CommandClass: recvTaskTreeMessage(dispatch, msg_class, classData); break; #endif case BroadcastClass: recvBroadcastMessage(dispatch); break; #ifndef NMP_IPC case MultiQueryClass: recvMultiQueryMessage(dispatch); break; #endif case SuccessClass: case FailureClass: recvSuccessFailureMessage(dispatch, msg_class); break; #ifndef NMP_IPC case FireDemonClass: LOG_MESSAGE2("%-9s %15s [%d]:", "FireDemon", dispatch->msg->msgData->name, *(int32 *)classData); Log_RefId(dispatch, LOGGING_MESSAGE); LOG_MESSAGE1("%10s", dispatch->org->modData->modName); LOG_MESSAGE1(" --> %-15s (Sent)", GET_S_GLOBAL(x_ipcServerModGlobal)->modData->modName); Log_Time(1); LOG_MESSAGE("\n"); fireDemonHnd(dispatch, (int32 *)classData); break; #endif case HandlerRegClass: case UNKNOWN: case ExecHndClass: #ifndef TEST_CASE_COVERAGE default: #endif X_IPC_ERROR1("ERROR: recvMessage: class not implemented: %d\n", msg_class); } }