Opened 7 years ago

Closed 20 months ago

#8829 closed enhancement (fixed)

Add wxSocketBase::GetSocket() returning socket descriptor

Reported by: botg Owned by:
Priority: low Milestone:
Component: network Version: stable-latest
Keywords: socket Cc: botg
Blocked By: Blocking:
Patch: yes

Description

Sometimes it is necessary to have access to the socket file descriptor, e.g. for use with WSAIoctl under Windows.

To make this possible, I've added the protected function wxSocketBase::GetInternalSocket which simply returns m_socket. From there on, the program can get the file descriptor from GSocket which has everything declared public. According to tn0020.txt, this shouldn't change the ABI.

Leave this function undocumented since it should rarely be used and virtually all usage scenarios are platform specific and not portable at all.

Attachments (2)

socket.patch download (463 bytes) - added by botg 7 years ago.
getsocket.patch download (4.2 KB) - added by lpoujoulat 20 months ago.

Download all attachments as: .zip

Change History (13)

Changed 7 years ago by botg

comment:1 Changed 7 years ago by botg

Patch is against WX_2_8_BRANCH and also applies against the trunk.

comment:2 Changed 7 years ago by vadz

First of all, while this doesn't change the ABI, the function should still be wrapped in wxABI_VERSION check and present in version-script.in.

Second, while I don't dispute that such function can be desirable, I don't think it makes sense to make it return GSocket because it's not at all impossible that in the future this entire class disappears (it's basically useless...). So what about adding GetSocket() returning directly SOCKET/int (do we need wxSOCKET_T?)? This function would be public and documented.

Thanks

comment:3 Changed 7 years ago by botg

What would be the correct type for sockets on wxMac?

Anyhow, I've hit the next problem: In order to enable a large TCP Window scale, I need to set SO_SNDBUF or SO_RVCBUF to >=64k _before_ calling Connect, yet this isn't possible with wxSocket at all, it's missing a 2-stage Create/Connect.

Would SetSocketBufferSizes(int snd, int recv) be a good solution, together with some new member variables? Then somewhere in GSocket::Connect the corresponding setsockopt calls would have to be made.

comment:4 Changed 7 years ago by vadz

Mac OS X is just Unix so I guess it uses ints like anything else and I'd still prefer to have a function returning this instead of GSocket.

Unfortunately I don't see any ABI-compatible solution to your SO_XXXBUF problem...

comment:5 Changed 7 years ago by sf-robot

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).

comment:6 Changed 20 months ago by lpoujoulat

  • Component set to network
  • Keywords socket added
  • Status changed from closed to reopened
  • Type set to build error
  • Version set to 2.9-svn

Hello all,

I run into the problem of setting the KEEPALIVE per connection timeout values (which is very platform specific), and I need to get access to the socket descriptor.

I'd like to add the GetSocket() you have defined in this tracker item. I'd gladly make the patch against 2.9, but I don't see where to define the wxSOCKET_T type.

Regards
Laurent

comment:7 Changed 20 months ago by vadz

  • Cc vadz removed
  • Patch unset
  • Status changed from reopened to confirmed
  • Summary changed from Add wxSocketBase::GetInternalSocket to Add wxSocketBase::GetSocket() returning socket descriptor

I'd define it in source:wxWidgets/trunk/include/wx/socket.h, why not?

We should also probably replace the use of SOCKET with wxSOCKET_T if we define it.

Changed 20 months ago by lpoujoulat

comment:8 Changed 20 months ago by lpoujoulat

  • Patch set
  • Type changed from build error to enhancement

Here is the patch against 2.9. Tested with MSVC2010 and MinGW both 32 and 64 bits. Need to be tested with Linux and OSX.

I replaced SOCKET with wxSOCKET_T only in the common socket parts, but not in MSW implementation as I think it's better to keep the original types in specific implementation.

Regards

comment:9 Changed 20 months ago by vadz

Could you please check if typedefing wxSOCKET_T as wxUIntPtr works without problems under Windows? I'd rather do this than include windows.h from a public header.

TIA!

P.S. No need to redo the patch, I can update this myself, especially as I've already done a couple of other cosmetic changes.

comment:10 Changed 20 months ago by lpoujoulat

I've checked with wxUIntPtr and it works. (This would have been suprising that it does not, as SOCKET is defined as the windows equivalent)

comment:11 Changed 20 months ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [73837]) Add wxSocketBase::GetSocket().

Provide direct access to the underlying socket descriptor.

Closes #8829.

Note: See TracTickets for help on using tickets.