Hi,

Often, the tipc_connect2port() routine is called in a callback routine.
The one I've used is after getting a connection request from a remote.
The steps would be:

Register the callback when a port is created with the tipc_createport()
call.  Some of the callbacks are:
  tipc_msg_event
  tipc_named_msg_event
  tipc_conn_msg_event
The first message in would trigger either a tipc_msg_event or
tipc_named_msg_event callback.  You would then call tipc_connect2port()
passing in the port information that was passed to you in the orig
parameter (or first create a brand new port and keep your first one as a
listening port like a listening socket).

After that, you should expect any new data to call the
tipc_conn_msg_event callback function (of the original or newly created
port as applicable).

Here is a basic example of one way to do this.  A port is created, a
message sent to a published name (which I already know exists).  Many
bits deleted for clarity that have nothing to do with the example.  And
maybe some of this is wrong - I haven't looked at it in a while.
Experiment.

Another example is in TIPC in how the topology server creates a new port
when it receives a connection request.  This can bee seen in
tipc_topsrv.c in the routine subscr_named_msg_event() which is a
callback registered with the topology server port.


/*****************************************************************
 *
 * c_continue_cb - call back after congestion has abated on connected
port
 *
 * where:
 * 
 * usr_handle = used for server connection number
 * port_ref = port number that was congested
 * 
 * RETURNS:  N/A
 */

static void c_continue_cb(void *usr_handle,
                               u32 port_ref)
{
    /* higprintf("continue_cb: entry\n"); */
    continueCb ++;
    /* send data directly from callBack or signal another process to do
something */
    SEND or SEND_TRIGGER;
}

/*****************************************************************
 *
 * msg_event_cb - call back for a message event
 *
 * Used in this code to receive the first and only reply message from
 * the blastee before we start blasting messages.
 *  
 * where:
 * 
 * buf = data packet
 * size = number of bytes per "blast"
 * 
 * RETURNS:  N/A
 */

static void msg_event_cb(void *usr_handle,
                               u32 port_ref,
                               struct sk_buff **buf,
                               unsigned char const *data,
                               unsigned int size,
                               unsigned int importance, 
                               struct tipc_portid const *orig,
                               struct tipc_name_seq const *dest)
{
    /* send data directly from callBack or signal another process to do
something */
    SEND or SEND_TRIGGER;
}


/*****************************************************************
 *
 * conn_msg_event_cb - call back for a connection message event
 *
 * Used in this code to receive a connecting message from the remote
 *  
 * where:
 * 
 * buf = data packet
 * data = pointer to the actual data (if any)
 * size = number of bytes per "blast"
 * 
 * RETURNS:  N/A
 */

static void conn_msg_event_cb(void *usr_handle,
                              u32 port_ref,
                              struct sk_buff **buf,
                              unsigned char const *data,
                              unsigned int size)
{
    /* send data directly from callBack or signal another process to do
something */
    SEND or SEND_TRIGGER;
}

/*****************************************************************
 *
 * c_named_msg_event_cb - call back for a named message event
(connected)
 *
 * Used in this code to receive the first message from the blaster
 * and then to send back any vital information to the blaster before
 * it starts blasting packets.
 *  
 * where:
 * 
 * buf = data packet
 * size = number of bytes per "blast"
 * 
 * RETURNS:  N/A
 */

static void c_named_msg_event_cb(void *usr_handle,
                               u32 port_ref,
                               struct sk_buff **buf,
                               unsigned char const *data,
                               unsigned int size,
                               unsigned int importance, 
                               struct tipc_portid const *orig,
                               struct tipc_name_seq const *dest)
{
    int res = 0;

    /* make a connection to this port */
    res = tipc_connect2port(port_ref, orig);
    [ do something with the result if required ]
}

STATUS blasterNativeTIPC1 (
    int size,                           /* packet size to test */
    int socketType                      /* socket type to test */
)
    {
    int              res;               /* result value */
    struct tipc_name name;              /* name to send to */
    u32              port_ref;  /* created port reference */
    struct iovec     msg_sect;  /* iovec for data */
    int              retval;            /* result to return for routine
*/
    int              i;                 /* loop counter */
    int              nsent;             /* how many bytes sent */

    /* initialize and check parameters */
    retval = ERROR;

    res = tipc_attach(&port_ref, NULL, NULL);
    if (res)
        return res;

    /* set up addressing */
    name.type = TIPC_EXPERIMENT_TYPE;
    name.instance = TIPC_EXPERIMENT_INSTANCE;
    msg_sect.iov_base = globalBuffer;
    msg_sect.iov_len = size;

    /* Create the new port */
    res = tipc_createport(port_ref, NULL, TIPC_LOW_IMPORTANCE,
                            NULL, NULL, NULL,
                            msg_event_cb, c_named_msg_event_cb,
conn_msg_event_cb,
                            c_continue_cb, &port_ref);
    if (res)
            return res;
            
    /* send first message to port */
    tipc_send2name(port_ref, 
                       &name, 
                       0 /* domain of 0:own zone */,
                       1 /* num_sect */,
                       msg_sect);

    /* Let the callbacks take care of everything */

    /* wait for the whole process to be completed */
    [ receive a signal that everything is completed ]

    /* everything looks good, set return value */
    retval = OK;
    
    res = tipc_shutdown(port_ref);
    if (res)
        {
        retval = res;
        }
    res = tipc_deleteport(port_ref);
    if (res)
        {
        retval = res;
        }
    return retval;
    }
 
Thanks,
Elmer


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Erich Focht
Sent: Friday, February 22, 2008 12:05 PM
To: [email protected]
Subject: [tipc-discussion] port name -> port_id ?

Hello,

with the native interface I'd like to do (inside a kernel module):

   tipc_connect2port(myref, subscr_service);

I know the target port name {1, 1} but how can I get the port_id, which
is required as argument to tipc_connect2port? The function
tipc_nametbl_translate isn't exported...

Thanks,
Erich

------------------------------------------------------------------------
-
This SF.net email is sponsored by: Microsoft Defy all challenges.
Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to