How to get socket descriptor from nsISocketTransport

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get socket descriptor from nsISocketTransport

Abhijit-2
 Hi All,

 I am trying to obtain socket descriptor from a Socket Transport
object. However, I am unable to obtain a valid descriptor, and I was
wondering if some one could point out what I am doing wrong. Here is
what I am doing to get socket descriptor:

 1. First, an nsiSocketTransport object is created in Javascript Code
using a SocketTransportService object:
var currTransport = mySockService.createTransport(null, 0,
currHostName, currPort, null);

 2. Now, I am passing currTransport to a C++ xpcom component as an
object with interface nsISocketTransport. In the C++ code, I call
GetFileDescriptor on the currTransport object.
 NS_IMETHODIMP getDescFromTransport(nsISocketTransport *sockTransport)
 {
  PRFileDesc *fd;
  ...
  if (NS_FAILED(sockTransport->GetFileDescriptor(&fd)))
        {
          return NS_OK;
        }
  ...
 }
 I noticed that after calling GetFileDescriptor, fd is set to a null
value.

 I think fd should not contain a null value and should point to the
socket descriptor for the socket connection that has been established.
Please let me know if this is the expected behaviour. Do I need to do
something more with sockTransport in order to obtain a valid file
descriptor using GetFileDescriptor()?

 Thanks,
 Abhijit

_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: How to get socket descriptor from nsISocketTransport

Christian Biesinger
Abhijit wrote:
>   if (NS_FAILED(sockTransport->GetFileDescriptor(&fd)))

(Wjat's GetFileDescriptor? I can't find such a function in my Gecko
source code)

>  I think fd should not contain a null value and should point to the
> socket descriptor for the socket connection that has been established.

You'll have to wait until DNS resolution is complete at least, no? It'd
probably be wise to wait until the connection is established too.

That is, wait for a STATUS_CONNECTING_TO (DNS lookup complete, socket
created, connecting) or STATUS_CONNECTED_TO (connection established)
message (via nsITransportEventSink).

-biesi
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: How to get socket descriptor from nsISocketTransport

Abhijit-2
In reply to this post by Abhijit-2
Hi Christian:

Christian Biesinger wrote:
> Abhijit wrote:
> >   if (NS_FAILED(sockTransport->GetFileDescriptor(&fd)))
>
> (Wjat's GetFileDescriptor? I can't find such a function in my Gecko
> source code)
>

 Yes, GetFileDescriptor is not a member in the IDL file for
nsISocketTransport.

> >  I think fd should not contain a null value and should point to the
> > socket descriptor for the socket connection that has been established.
>
> You'll have to wait until DNS resolution is complete at least, no? It'd
> probably be wise to wait until the connection is established too.
>
> That is, wait for a STATUS_CONNECTING_TO (DNS lookup complete, socket
> created, connecting) or STATUS_CONNECTED_TO (connection established)
> message (via nsITransportEventSink).

 I agree. I tried accessing the file descriptor after sending and
receiving data on the Socket Transport (via input and output streams)
and I did get a valid socket descriptor.

 Thanks for the help!
 Abhijit

>
> -biesi

_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib