[Vortex] How to correctly close a connection?

Francis Brosnan Blazquez francis at aspl.es
Mon Oct 6 18:32:17 CEST 2008


Hi Robert,

> Hi, I have the following setup. I use vortex together with a scripting  
> language. For this I have coded some high-level function in C that are  
> used by the scripting language and these high-level functions call the  
> vortex functions.
> 
> The script can issue things like send-file. Those calls return immediatly,  
> while my functions & vortex functions do the transfer ansynchronosly.
> 
> At the moment I have a problem when the initiator (client) of a conneciton  
> closes it. I get a seg-fault on the receiver (server).
> 
> So some questions:
> 
> 1. On the client I call
> 	- vortex_connection_shutdown
> 	- vortex_connection_close
> in this order. At the moment I know that no transfer is happening. Is this  
> the correct way?

This is correct. However, every on going transfer, in both sides, will
be cancelled.

> 2. I want to make sure that a call to disconnect from the script hangs as  
> long there is still a transfer running on the vortex side. So, blocking  
> the script. How can I check if vortex channels are still in use and wait  
> until I can close a connection gracefully?

It depends on your protocol. Who is going to close the connection, the
server (frame received) or the client? or both?

> 3. On the server I use an on_connection_closed handler. This handler just  
> sends a message to the script and returns. I expect that the server is  
> than going back into the listening loop. Is this correct? 

This is right. If you receive this notification, then the connection was
notified to be closed. However, the connection is still accesible until
all vortex subsystem drop its references to the connection (and those
ones created by your code)..

> The crash  
> happens after the on_connection_closed handler is called.

But, it crashes when the connection that was notified to be closed is
used again? or...?

If so, the connection must not be used once the handler finishes. If you
want to do so you'll have to play with references
(vortex_connection_ref/unref).

Cheers!

> Any help is appreciated. Thanks.
> 
-- 
Francis Brosnan Blazquez <francis at aspl.es>
Advanced Software Production Line, S.L.



More information about the Vortex mailing list