PDA

View Full Version : Question on STREAMs based socket


tulobear
04-02-2003, 02:23 PM
Hi, I have written a series of TPI APIs such as tpi_bind, tpi_connect, tpi_send, tpi_recv, tpi_close for application level. A client using these TPI APIs successfully communicates with a server using standard socket APIs. When I try to write tpi_accept for server application, I found there is no corresponding T_primitives(for example, like: T_LISTEN_REQ) in the header file /sys/include/tihdr.h . As says in Richard steven's book, a socket must be turned to passive mode by using listen(fd,queueno) before it can receive connection request.
So, my question is how to tell the device driver- "/dev/tcp" to "listen" on a bound socket? Thanks a lot!!!
(Work enviroment is Sun Os 5.8 Sparc)

zapdog
04-06-2003, 08:40 AM
From your description, I assume you are using xti.

Short answer: t_bind().

Longer answer: in the t_bind(fd, req, ret) call, "req" is a t_bind structure that contains the element "qlen". If you set qlen > 0, the O/S will start queueing connects to the transport endpoint.

Typical series of events:

Bind the fd with (qlen > 0). Use poll() to wait for an event (connection) on the fd, setting the requested events to POLLIN. Once an event occurs, use t_listen() to consume the event. You will probably want to establish a transport endpoint using a new fd, so issue a t_open(), and t_bind(new_fd, NULL, NULL). Issue a t_accept() to accept the connection, using the new fd.

Cheers, Zapdog

tulobear
04-06-2003, 11:25 AM
Thanks a lot,zapdog. :)
Your suggestion is right! I forgot to set the "qlen" when binding a fd for a server. Actually, I am not using xti. I am trying to use TPI to provide a series of APIs for user application(such as xti did). All the primitives of TPI are defined in sys/tihdr.h. Follow your suggestion, server can getmsg "T_conn_req" from client now. But I still do not know how to create another fd to accept this request. I have tried to send "T_conn_res" and "T_conn_con" msg back to kernel, but "T_error_ack" was returned back from device driver "/dev/tcp".

Anyway, thanks again for your kindly help!

zapdog
04-07-2003, 08:07 AM
Whoa. Kernel Streams TPI message based interface. I have never used this API but I will not let that stop me from posting an opinion.

Based on what I see in the tihdr.h file, you should be using T_conn_res, the T_conn_conn primitive is sent by the transport provider.

When you get the T_error_ack message, the message should identify one of the error codes in the tpicommon.h file. In XTI this would be the value of t_errno.

The only errors that makes sense to me would be TRESADDR: Connection acceptor-listener addresses not same but required by transport or TRESQLEN: Connector acceptor has listen queue length limit greater than zero. Both errors would indicate that the fd (stream) that you are trying to accept the connection on has not been bound properly. Either you have set (qlen > 0) or not bound it to the same address (port) as the stream on which the connection indication was received.

Hope this helps. Let us know how it goes.

Cheers, Zapdog

Uzume
04-09-2003, 09:23 AM
Interested parties can find documentation on obsolete X/Open Transport Interface (XTI) (http://www.opengroup.org/onlinepubs/009619199/) here.

tulobear
04-14-2003, 03:52 AM
Hi, zapdog
I have not raveled out the problem yet. But I have reserved a book from library - "UNIX System V network programming /, Rago, Stephen A. 02/07/2003". There are detailed illustrations on TPI. But I am upside down for my exam these days. I will crack this problem later and let u know the progress.

Thanks Uzume too.