]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Inet protocol sends HELLO as the first message after connect()
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 27 May 2009 21:34:29 +0000 (23:34 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 27 May 2009 21:34:29 +0000 (23:34 +0200)
This allows the receiver to know sender's listening address, which is different
from the address of the connect()ed socket. Besides the address, also orb_id is
sent, which makes debugging easier.

It this approach is found successful, this functionality should be moved to
iop.c and protocols should have new connect callback which will be called by iop
if the peer was never contacted.

src/Makefile.omk
src/iop.c
src/iop.h
src/proto_inet.c

index 9461a70aa83e75986c59a38a7fbab50f4544e149..8876fcc6e09285687468f23bb5e7a4a945b4728a 100644 (file)
@@ -40,6 +40,7 @@ renamed_include_HEADERS += \
        $(call to_forb_subdir, request.h) \
        $(call to_forb_subdir, syncobj.h) \
        $(call to_forb_subdir, server_id.h) \
+       $(call to_forb_subdir, peer.h) \
        $(call to_forb_subdir, uuid.h)
 
 renamed_include_GEN_HEADERS = \
index f6dca49e57319e83b43b12865963f697447ea549..74d817c67b62b24df987848bcaf166f001050cdc 100644 (file)
--- a/src/iop.c
+++ b/src/iop.c
@@ -131,6 +131,32 @@ forb_iop_prepare_hello(FORB_CDR_Codec *codec,
        return CORBA_TRUE;
 }
 
+int forb_iop_send_hello_to(forb_peer_t *peer)
+{
+       forb_port_t *port = peer->port;
+       FORB_CDR_Codec codec;
+       int ret;
+       FORB_CDR_codec_init_static(&codec, port->forb->orb);
+       if (!FORB_CDR_buffer_init(&codec, 1024, 0))
+               return -1;              
+       if (!FORB_CDR_buffer_reset(&codec, forb_iop_MESSAGE_HEADER_SIZE)) {
+               ret = -1;
+               goto free;
+       }
+       if (!forb_iop_prepare_hello(&codec, &port->forb->server_id,
+                                   port->desc.addr,
+                                   port->desc.proto->serialize_addr,
+                                   port->forb->attr.orb_id)) {
+               ret = -1;
+               goto free;
+       }
+       ret = forb_proto_send(peer, &codec);
+       if (ret > 0) ret = 0;
+free:
+       FORB_CDR_codec_release_buffer(&codec);
+       return ret;
+}
+
 bool
 forb_iop_process_message_header(forb_iop_message_header *mh, FORB_CDR_Codec *codec)
 {
@@ -451,6 +477,13 @@ process_hello(forb_port_t *port, FORB_CDR_Codec *codec)
                                forb_free(peer_orb_id);
                        forb_peer_put(peer);
                } else {
+                       if (port->new_peer) {
+                               if (peer)
+                                       ul_logerr("Unahandled case - FORB_PEER_WANTED && port->new_peer\n");
+                               peer = port->new_peer;
+                               port->new_peer = NULL;
+                       }
+
                        forb_new_peer_discovered(port, peer, server_id, addr, peer_orb_id);
                }
        }
index 4dc764cfc72e13c510d36a43e4c9517e35a367a5..38971f6a28b32e9499e093ddaeda02ae60fab51d 100644 (file)
--- a/src/iop.h
+++ b/src/iop.h
@@ -60,6 +60,7 @@
 #include <forb/iop-idl.h>
 #include <forb/cdr.h>
 #include <forb/request.h>
+#include <forb/peer.h>
 
 CORBA_boolean
 forb_iop_prepend_message_header(FORB_CDR_Codec *codec, forb_iop_message_type mt);
@@ -92,4 +93,7 @@ forb_iop_discovery_thread(void *arg);
 void
 forb_request_send(forb_request_t *req, CORBA_Environment *env);
 
+int
+forb_iop_send_hello_to(forb_peer_t *peer);
+
 #endif
index 3281aed57007dc8205bd59c9ef62f19c9b0e9652..5cef70dc70f203a0c27d0a8625f9da52f72d0452 100644 (file)
@@ -60,6 +60,7 @@
 #include <unistd.h>
 #include <forb/config.h>
 #include "discovery.h"
+#include "iop.h" /* FIXME: Sending hello should be handled in IOP layer */
 
 /**
  * @file   proto_inet.c
@@ -145,7 +146,7 @@ inet_deserialize_addr(FORB_CDR_Codec *codec, void **addr)
        return ret;
 }
 
-static struct inet_peer *
+static int
 inet_connect(forb_peer_t *peer)
 {
        struct inet_peer *ipeer;
@@ -155,7 +156,7 @@ inet_connect(forb_peer_t *peer)
 
        if (!addr) {
                ul_logerr("No address to connect\n");
-               return NULL;
+               goto err;
        }
        ipeer = forb_malloc(sizeof(*ipeer));
        if (!ipeer)
@@ -186,14 +187,22 @@ inet_connect(forb_peer_t *peer)
                goto err_close;
        }
 
+       peer->proto_priv = ipeer;
+
+#ifndef TEST /* FIXME: Move hello to IOP, introduce proto connect callback */
+       ret = forb_iop_send_hello_to(peer);
+       if (ret) {
+               goto err_close;
+       }
+#endif
 
-       return ipeer;
+       return 0;
 err_close:
        close(ipeer->socket);
 err_free:
        forb_free(ipeer);
 err:
-       return NULL;
+       return -1;
        
 }
 
@@ -204,12 +213,11 @@ inet_send(forb_peer_t *peer, const void *buf, size_t len)
        ssize_t ret, sent;
 
        if (!ipeer) {
-               ipeer = inet_connect(peer);
-               if (!ipeer) {
-                       return -1;
+               ret = inet_connect(peer);
+               if (ret) {
+                       return ret;
                }
-               peer->proto_priv = ipeer;
-               
+               ipeer = peer->proto_priv;
        }
 
        sent = 0;
@@ -287,7 +295,6 @@ inet_accept_connection(forb_port_t *port)
                        peer->port = port;
                        peer->state = FORB_PEER_DISCOVERED;
                        inet_port_new_peer_insert(p, peer);
-                       //printf("New connection d=%d\n", client);
                } else {
                        forb_peer_put(peer);
                }