Bool dcop_protocol_setup() { char * vendor = 0L; char * release = 0L; IcePointer clientData = 0; int majorVersion = 0; int minorVersion = 0; int status = 0; char errBuf[BUFFER_SIZE]; status = IceProtocolSetup( dcop_ice_conn, dcop_major_opcode, clientData, True, &(majorVersion), &(minorVersion), &(vendor), &(release), BUFFER_SIZE, errBuf ); return ( (status == IceProtocolSetupSuccess) && (IceConnectionStatus(dcop_ice_conn) == IceConnectAccepted) ); }
static void NewConnectionXtProc(XtPointer client_data, int *source, XtInputId *id) { IceConn ice_conn; char *connstr; IceAcceptStatus status; if (shutdownInProgress) { /* * Don't accept new connections if we are in the middle * of a shutdown. */ return; } ice_conn = IceAcceptConnection((IceListenObj) client_data, &status); if (! ice_conn) { if (verbose) printf ("IceAcceptConnection failed\n"); } else { IceConnectStatus cstatus; while ((cstatus = IceConnectionStatus (ice_conn))==IceConnectPending) { XtAppProcessEvent (appContext, XtIMAll); } if (cstatus == IceConnectAccepted) { if (verbose) { printf ("ICE Connection opened by client, IceConn fd = %d, ", IceConnectionNumber (ice_conn)); connstr = IceConnectionString (ice_conn); printf ("Accept at networkId %s\n", connstr); free (connstr); printf ("\n"); } } else { if (verbose) { if (cstatus == IceConnectIOError) printf ("IO error opening ICE Connection!\n"); else printf ("ICE Connection rejected!\n"); } IceCloseConnection (ice_conn); } } }
static gboolean ice_connection_accept (GIOChannel *channel, GIOCondition condition, gpointer watch_data) { IceConnectStatus cstatus; IceAcceptStatus astatus; IceListenObj ice_listener = (IceListenObj) watch_data; IceConn ice_conn; ice_conn = IceAcceptConnection (ice_listener, &astatus); if (astatus != IceAcceptSuccess) { g_warning ("Failed to accept ICE connection on listener %p", (gpointer) ice_listener); } else { /* Wait for the connection to leave pending state */ do { IceProcessMessages (ice_conn, NULL, NULL); } while ((cstatus = IceConnectionStatus (ice_conn)) == IceConnectPending); if (cstatus != IceConnectAccepted) { if (cstatus == IceConnectIOError) { g_warning ("I/O error opening ICE connection %p", (gpointer) ice_conn); } else { g_warning ("ICE connection %p rejected", (gpointer) ice_conn); } IceSetShutdownNegotiation (ice_conn, False); IceCloseConnection (ice_conn); } } return TRUE; }
void KSMServer::newConnection( int /*socket*/ ) { IceAcceptStatus status; IceConn iceConn = IceAcceptConnection( ((KSMListener*)sender())->listenObj, &status); if( iceConn == NULL ) return; IceSetShutdownNegotiation( iceConn, False ); IceConnectStatus cstatus; while ((cstatus = IceConnectionStatus (iceConn))==IceConnectPending) { (void) IceProcessMessages( iceConn, 0, 0 ); } if (cstatus != IceConnectAccepted) { if (cstatus == IceConnectIOError) kDebug( 1218 ) << "IO error opening ICE Connection!"; else kDebug( 1218 ) << "ICE Connection rejected!"; (void )IceCloseConnection (iceConn); return; } // don't leak the fd fcntl( IceConnectionNumber(iceConn), F_SETFD, FD_CLOEXEC ); }
Bool dcop_call( const char * appId, const char * remApp, const char * remObjId, const char * remFun, const char * data, int dataLength, char ** replyType, char ** replyData, int * replyDataLength ) { IceReplyWaitInfo waitInfo; IceProcessMessagesStatus status; struct dcop_reply_struct replyStruct; char * pos = 0L; char * outputData = 0L; int outputDataLength = 0; int temp = 0; Bool success = False; Bool readyRet = False; struct DCOPMsg * pMsg; fprintf(stderr, "dcop_call() ...\n"); if (0 == dcop_ice_conn) { fprintf(stderr, "Try running dcop_register(), moron\n"); return False; } temp += strlen(appId); temp += strlen(remApp); temp += strlen(remObjId); temp += strlen(remFun); temp += dataLength; temp += 1024; /* Extra space for marshalling overhead */ outputData = (char *)malloc(temp); temp = 0; pos = outputData; pos = dcop_write_string(pos, appId); pos = dcop_write_string(pos, remApp); pos = dcop_write_string(pos, remObjId); pos = dcop_write_string(pos, remFun); pos = dcop_write_int(pos, dataLength); outputDataLength = pos - outputData; IceGetHeader( dcop_ice_conn, dcop_major_opcode, DCOPCall, sizeof(struct DCOPMsg), struct DCOPMsg, pMsg ); pMsg->length += outputDataLength + dataLength; IceSendData(dcop_ice_conn, outputDataLength, outputData); IceSendData(dcop_ice_conn, dataLength, (char *)data); IceFlush(dcop_ice_conn); free(outputData); outputData = NULL; if (IceConnectionStatus(dcop_ice_conn) != IceConnectAccepted) { fprintf(stderr, "dcop_call(): Connection not accepted\n"); return False; } waitInfo.sequence_of_request = IceLastSentSequenceNumber(dcop_ice_conn); waitInfo.major_opcode_of_request = dcop_major_opcode; waitInfo.minor_opcode_of_request = DCOPCall; replyStruct.status = DCOP_REPLY_PENDING; replyStruct.replyId = dcop_reply_id++; replyStruct.replyType = replyType; replyStruct.replyData = replyData; replyStruct.replyDataLength = replyDataLength; waitInfo.reply = (IcePointer)(&replyStruct); readyRet = False; do { fprintf(stderr, "dcop_call(): Doing IceProcessMessages\n"); status = IceProcessMessages(dcop_ice_conn, &waitInfo, &readyRet); if (status == IceProcessMessagesIOError) { fprintf(stderr, "dcop_call(): IceProcessMessagesIOError\n"); IceCloseConnection(dcop_ice_conn); return False; } fprintf(stderr, "dcop_call(): readyRet == %s\n", readyRet ? "True" : "False"); } while (!readyRet); fprintf(stderr, "dcop_call(): Finished\n"); return (replyStruct.status == DCOP_REPLY_OK) ? True : False; }
Bool dcop_send_signal( const char * receiving_app, const char * object, const char * function, char * data, int dataLength ) { char * pos = 0L; char * header = 0L; unsigned int headerLength = 0; struct DCOPMsg * pMsgPtr = 0; static const char* sAnonymous = "anonymous"; if (0 == dcop_ice_conn) { fprintf(stderr, "Try running dcop_attach(), moron\n"); return False; } /* * First let ICE initialize the ICE Message Header and give us a pointer to * it (ICE manages that buffer internally) */ IceGetHeader( dcop_ice_conn, dcop_major_opcode, DCOPSend, sizeof(struct DCOPMsg), struct DCOPMsg, pMsgPtr ); /* * Marshall the arguments for the DCOP message header (callerApp, destApp, * destObj, destFunc. The last argument is actually part of the data part of * the call, but we add it to the header. It's the size of the marshalled * argument data. In Qt it would look like TQDataStream str( ... ) str << * callerApp << destApp << destObj << destFun << * argumentQByteArrayDataStuff; (where as str is the complete data stream * sent do the dcopserver, excluding the ICE header) As the TQByteArray is * marshalled as [size][data] and as we (below) send the data in two chunks, * first the dcop msg header and the the data, we just put the [size] field * as last field into the dcop msg header ;-) */ headerLength = strlen(sAnonymous) + 1 + strlen(receiving_app) + 1 + strlen(object) + 1 + strlen(function) + 1 + 4*5; /* 4 string lengths + 1 int */ header = (char *)malloc(headerLength); pos = header; pos = dcop_write_string(pos, sAnonymous); pos = dcop_write_string(pos, receiving_app); pos = dcop_write_string(pos, object); pos = dcop_write_string(pos, function); pos = dcop_write_int(pos, dataLength); headerLength = pos - header; pMsgPtr->key = dcop_key; /* * The length field tells the dcopserver how much bytes the dcop message * takes up. We add that size to the already by IceGetHeader initialized * length value, as it seems that under some circumstances (depending on the * DCOPMsg structure size) the length field is aligned/padded. */ pMsgPtr->length += headerLength + dataLength; /* First let's send the dcop message header. * IceSendData automatically takes care of first sending the Ice Message * Header (outbufptr > outbuf -> flush the connection buffer) */ IceSendData(dcop_ice_conn, headerLength, header); /* Now the function argument data */ IceSendData(dcop_ice_conn, dataLength, data); /* Send it all ;-) */ IceFlush(dcop_ice_conn); free(header); if (IceConnectionStatus(dcop_ice_conn) != IceConnectAccepted) return False; return True; }
static void ProcessPMInput ( int * nfds, fd_set * rinit, int pm_idx) { IceProcessMessagesStatus process_status; switch (IceConnectionStatus(pm_conn_array[pm_idx]->ice_conn)) { case IceConnectPending: /* * for some reason this connection still isn't ready for * reading, so return and try next readable */ (void) IceProcessMessages(pm_conn_array[pm_idx]->ice_conn, NULL, NULL); break; case IceConnectAccepted: /* * you're ready to read the PM data, allocate and send back * your client listen port, etc., etc.; do this inside * FWPprocessMessages() by calling IceProcessMessages() * [NOTE: The NULL args set it up for non-blocking] */ process_status = IceProcessMessages(pm_conn_array[pm_idx]->ice_conn, NULL, NULL); switch (process_status) { case IceProcessMessagesSuccess: /* * you read the server data, allocated a listen port * for the remote client and wrote it back to the PM, * so you don't need to do anything more until PM * closes the connection (NOTE: Make sure we don't * do this more than once!!) */ break; case IceProcessMessagesIOError: case IceProcessMessagesConnectionClosed: if (process_status == IceProcessMessagesIOError) /* * there was a problem with the connection, close * it explicitly */ IceCloseConnection(pm_conn_array[pm_idx]->ice_conn); else /* * the connection somehow closed itself, so don't call * IceCloseConnection */ ; /* * reset the select() readables mask and nfds, free * the buffer memory on this array element, reset the * pointer to NULL and return */ FD_CLR(pm_conn_array[pm_idx]->fd, rinit); *nfds = max(*nfds, pm_conn_array[pm_idx]->fd + 1); free(pm_conn_array[pm_idx]); pm_conn_array[pm_idx] = NULL; break; default: /* * Should never get here since all of the return * codes from IceProcessMessages have been checked. */ (void) fprintf (stderr, "IceProcessMessages error\n"); } break; case IceConnectRejected: /* * don't know yet what to do in this case, but for now simply * output diagnostic and return to select() processing */ (void) fprintf (stderr, "PM IceConnectRejected\n"); break; case IceConnectIOError: /* * don't know yet what to do in this case, but for now simply * output diagnostic and return to select() processing */ (void) fprintf (stderr, "PM IceConnectIOError\n"); break; default: /* * Should never get here since all of the return * codes from IceConnectionStatus have been checked. */ (void) fprintf (stderr, "IceConnectionStatus error\n"); } }