GIOPSendBuffer * giop_send_buffer_use (GIOPVersion giop_version) { GIOPSendBuffer *buf; g_return_val_if_fail ( ((int) giop_version) >= 0 && giop_version < GIOP_NUM_VERSIONS, NULL); LINK_MUTEX_LOCK (send_buffer_list_lock); if (send_buffer_list) { GSList *ltmp; ltmp = send_buffer_list; send_buffer_list = g_slist_remove_link ( send_buffer_list, ltmp); LINK_MUTEX_UNLOCK (send_buffer_list_lock); buf = ltmp->data; g_slist_free_1 (ltmp); buf->num_used = buf->indirect_left = 0; if (giop_blank_wire_data) { int i; for (i = 0; i < buf->num_indirects_used; i++) memset (buf->indirects [i].ptr, 0, buf->indirects [i].size); } buf->num_indirects_used = 0; } else { LINK_MUTEX_UNLOCK (send_buffer_list_lock); buf = g_new0 (GIOPSendBuffer, 1); memcpy (buf->msg.header.magic, "GIOP", 4); buf->msg.header.flags = GIOP_FLAG_ENDIANNESS; buf->num_alloced = 8; buf->iovecs = g_new (struct iovec, 8); } memcpy (buf->msg.header.version, giop_version_ids [giop_version], 2); buf->giop_version = giop_version; g_assert (sizeof (buf->msg.header) == 12); giop_send_buffer_append_real ( buf, (guchar *)&buf->msg.header, 12); buf->msg.header.message_size = 0; buf->header_size = 12; return buf; }
void link_exec_command (LinkCommand *cmd) { int res = 0; if (link_in_io_thread ()) { link_dispatch_command (cmd, TRUE); return; } LINK_MUTEX_LOCK (link_cmd_queue_lock); if (LINK_WAKEUP_WRITE == -1) { /* shutdown main loop */ LINK_MUTEX_UNLOCK (link_cmd_queue_lock); link_dispatch_command (cmd, TRUE); return; } if (!link_cmd_queue) { char c = 'A'; /* magic */ #ifdef HAVE_WINSOCK2_H while ((res = send (LINK_WAKEUP_WRITE, &c, sizeof (c), 0)) == SOCKET_ERROR && (WSAGetLastError () == WSAEWOULDBLOCK)); #else while ((res = write (LINK_WAKEUP_WRITE, &c, sizeof (c))) < 0 && (errno == EAGAIN || errno == EINTR)); #endif } link_cmd_queue = g_list_append (link_cmd_queue, cmd); if (cmd_is_sync (cmd)) while (!((LinkSyncCommand *)cmd)->complete) g_cond_wait (link_cmd_queue_cond, link_cmd_queue_lock); LINK_MUTEX_UNLOCK (link_cmd_queue_lock); if (res < 0) g_error ("Failed to write to linc wakeup socket %d 0x%x(%d) (%d)", res, errno, errno, LINK_WAKEUP_WRITE); }
void CORBA_exception_free (CORBA_Environment *ev) { g_return_if_fail (ev != NULL); if (ev->_major != CORBA_NO_EXCEPTION) { LINK_MUTEX_LOCK (ORBit_RootObject_lifecycle_lock); CORBA_exception_free_T (ev); LINK_MUTEX_UNLOCK (ORBit_RootObject_lifecycle_lock); } }
void giop_recv_list_destroy_queue_entry (GIOPMessageQueueEntry *ent) { LINK_MUTEX_LOCK (giop_queued_messages_lock); #ifdef DEBUG g_warning ("Remove XX:%p:(%p) - %d", ent, ent->async_cb, g_list_length (giop_queued_messages)); #endif giop_queued_messages = g_list_remove (giop_queued_messages, ent); LINK_MUTEX_UNLOCK (giop_queued_messages_lock); giop_recv_destroy_queue_entry_T (ent); }
void giop_recv_list_zap (GIOPConnection *cnx) { GList *l, *next; GSList *sl, *notify = NULL; LINK_MUTEX_LOCK (giop_queued_messages_lock); for (l = giop_queued_messages; l; l = next) { GIOPMessageQueueEntry *ent = l->data; next = l->next; if (ent->cnx == cnx) { ent_lock (ent); dprintf (ERRORS, "Zap listener on dead cnx with buffer %p\n", ent->buffer); giop_recv_buffer_unuse (ent->buffer); ent->buffer = NULL; giop_recv_destroy_queue_entry_T (ent); if (giop_thread_io () && !ent->async_cb) giop_incoming_signal_T (ent->src_thread, GIOP_CLOSECONNECTION); ent_unlock (ent); if (ent->async_cb) notify = g_slist_prepend (notify, ent); giop_queued_messages = g_list_delete_link ( giop_queued_messages, l); } } LINK_MUTEX_UNLOCK (giop_queued_messages_lock); for (sl = notify; sl; sl = sl->next) { GIOPMessageQueueEntry *ent = sl->data; if (!ent->async_cb) { /* This should never happen */ g_warning ("Extraordinary recv list re-enterancy"); continue; } giop_invoke_async (ent); } g_slist_free (notify); }
void giop_send_buffer_unuse (GIOPSendBuffer *buf) { int i; for (i = 0; i < buf->num_indirects_used; i++) { if (buf->indirects[i].size > GIOP_CHUNK_SIZE) { buf->indirects [i].size = GIOP_CHUNK_SIZE; buf->indirects [i].ptr = g_realloc (buf->indirects [i].ptr, buf->indirects [i].size); } } LINK_MUTEX_LOCK (send_buffer_list_lock); send_buffer_list = g_slist_prepend (send_buffer_list, buf); LINK_MUTEX_UNLOCK (send_buffer_list_lock); }
static void MateCORBA_ORB_shutdown_servers (CORBA_ORB orb) { LINK_MUTEX_LOCK (orb->lock); if (orb->objrefs) { g_hash_table_foreach (orb->objrefs, strip_object_profiles, NULL); g_hash_table_destroy (orb->objrefs); orb->objrefs = NULL; } IOP_shutdown_profiles (orb->profiles); orb->profiles = NULL; g_slist_foreach (orb->servers, (GFunc) g_object_unref, NULL); g_slist_free (orb->servers); orb->servers = NULL; LINK_MUTEX_UNLOCK (orb->lock); }
void giop_recv_list_setup_queue_entry (GIOPMessageQueueEntry *ent, GIOPConnection *cnx, CORBA_unsigned_long msg_type, CORBA_unsigned_long request_id) { ent->src_thread = giop_thread_self (); ent->async_cb = NULL; ent->cnx = giop_connection_ref (cnx); ent->msg_type = msg_type; ent->request_id = request_id; ent->buffer = NULL; LINK_MUTEX_LOCK (giop_queued_messages_lock); #ifdef DEBUG g_warning ("Push XX:%p:(%p) - %d", ent, ent->async_cb, g_list_length (giop_queued_messages)); #endif giop_queued_messages = g_list_prepend (giop_queued_messages, ent); LINK_MUTEX_UNLOCK (giop_queued_messages_lock); }
static gpointer link_io_thread_fn (gpointer data) { g_main_loop_run (link_thread_loop); /* FIXME: need to be able to quit without waiting ... */ /* Asked to quit - so ... * a) stop accepting inputs [ kill servers ] * b) flush outgoing queued data etc. (oneways) * c) unref all leakable resources. */ link_connections_close (); /* A tad of shutdown */ LINK_MUTEX_LOCK (link_cmd_queue_lock); if (LINK_WAKEUP_WRITE >= 0) { #ifdef HAVE_WINSOCK2_H closesocket (LINK_WAKEUP_WRITE); closesocket (LINK_WAKEUP_POLL); #else close (LINK_WAKEUP_WRITE); close (LINK_WAKEUP_POLL); #endif LINK_WAKEUP_WRITE = -1; LINK_WAKEUP_POLL = -1; } LINK_MUTEX_UNLOCK (link_cmd_queue_lock); if (link_main_source) { g_source_destroy (link_main_source); g_source_unref (link_main_source); link_main_source = NULL; } return NULL; }
void MateCORBA_ORB_start_servers (CORBA_ORB orb) { LinkProtocolInfo *info; LinkConnectionOptions create_options = 0; LINK_MUTEX_LOCK (orb->lock); if (orb->servers) { /* beaten to it */ LINK_MUTEX_UNLOCK (orb->lock); return; } if (matecorba_local_only) create_options |= LINK_CONNECTION_LOCAL_ONLY; if (matecorba_local_only || (matecorba_use_usocks && !(matecorba_use_ipv4 || matecorba_use_ipv6 || matecorba_use_irda || matecorba_use_ssl))) link_use_local_hostname (LINK_NET_ID_IS_LOCAL); else { do { if (!matecorba_net_id) break; if (!strcmp(matecorba_net_id, "local")) { link_use_local_hostname (LINK_NET_ID_IS_LOCAL); break; } if (!strcmp(matecorba_net_id, "short")) { link_use_local_hostname (LINK_NET_ID_IS_SHORT_HOSTNAME); break; } if (!strcmp(matecorba_net_id, "fqdn")) { link_use_local_hostname (LINK_NET_ID_IS_FQDN); break; } if (!strcmp(matecorba_net_id, "ipaddr")) { link_use_local_hostname (LINK_NET_ID_IS_IPADDR); break; } link_set_local_hostname(matecorba_net_id); } while (0); } if (!matecorba_ipname) matecorba_ipname = link_get_local_hostname(); else link_set_local_hostname(matecorba_ipname); for (info = link_protocol_all (); info->name; info++) { GIOPServer *server; if (!MateCORBA_proto_use (info->name)) continue; server = giop_server_new ( orb->default_giop_version, info->name, matecorba_ipname, matecorba_ipsock, create_options, orb); if (server) { orb->servers = g_slist_prepend (orb->servers, server); if (!(info->flags & LINK_PROTOCOL_SECURE)) { if (!MateCORBA_proto_use ("SSL")) continue; server = giop_server_new ( orb->default_giop_version, info->name, NULL, NULL, LINK_CONNECTION_SSL | create_options, orb); if (server) orb->servers = g_slist_prepend (orb->servers, server); } #ifdef DEBUG fprintf (stderr, "ORB created giop server '%s'\n", info->name); #endif } #ifdef DEBUG else fprintf (stderr, "ORB failed to create giop server '%s'\n", info->name); #endif } orb->profiles = IOP_start_profiles (orb); LINK_MUTEX_UNLOCK (orb->lock); }
static gboolean handle_reply (GIOPRecvBuffer *buf) { GList *l; gboolean error; GIOPMessageQueueEntry *ent; CORBA_unsigned_long request_id; request_id = giop_recv_buffer_get_request_id (buf); error = FALSE; LINK_MUTEX_LOCK (giop_queued_messages_lock); for (l = giop_queued_messages; l; l = l->next) { ent = l->data; if (ent->request_id == request_id && ent->msg_type == buf->msg.header.message_type) break; } ent = l ? l->data : NULL; if (!ent) { if (giop_recv_buffer_reply_status (buf) == CORBA_SYSTEM_EXCEPTION) { /* * Unexpected - but sometimes a oneway * method invocation on a de-activated * object results in us getting a bogus * system exception in reply. */ } else { #ifdef G_ENABLE_DEBUG if (giop_debug_hook_unexpected_reply) giop_debug_hook_unexpected_reply (buf); else dprintf (ERRORS, "We received an unexpected reply\n"); #endif /* G_ENABLE_DEBUG */ error = TRUE; } } else if (ent->cnx != buf->connection) { #ifdef G_ENABLE_DEBUG if (giop_debug_hook_spoofed_reply) giop_debug_hook_spoofed_reply (buf, ent); #endif dprintf (ERRORS, "We received a bogus reply\n"); error = TRUE; } else { #ifdef DEBUG g_warning ("Pop XX:%p:%p - %d", ent, ent->async_cb, g_list_length (giop_queued_messages)); #endif giop_queued_messages = g_list_delete_link (giop_queued_messages, l); } LINK_MUTEX_UNLOCK (giop_queued_messages_lock); if (ent && !error) { gboolean async = FALSE; ent_lock (ent); ent->buffer = buf; if (giop_thread_io () && !ent->async_cb) giop_incoming_signal_T (ent->src_thread, GIOP_REPLY); else if (ent->async_cb) async = TRUE; ent_unlock (ent); if (async) giop_invoke_async (ent); buf = NULL; } giop_recv_buffer_unuse (buf); return error; }