Bug 2835 – std.socket.TcpSocket.connect doesn't actually connect

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-04-14T16:38:00Z
Last change time
2015-06-09T01:18:03Z
Keywords
patch, wrong-code
Assigned to
rsinfu
Creator
graham.stjack

Attachments

IDFilenameSummaryContent-TypeSize
322try.dTest casetext/x-dsrc3014
3242835_set-family.diffSet sin_family properly.text/plain776
567socket.diffpatch for std.sockettext/plain668

Comments

Comment #0 by graham.stjack — 2009-04-14T16:38:10Z
The attached code works in 2.0.26 and blocks on accept in 2.0.27
Comment #1 by graham.stjack — 2009-04-14T16:39:22Z
Created attachment 322 Test case
Comment #2 by bugs-d — 2009-04-15T12:40:01Z
Just a drive-by. Simplified testcase: --- import std.socket, std.stdio; void main() { // Replace 12345 with any unused port. auto address = new InternetAddress("127.0.0.1", 12345); try { auto client = new TcpSocket(); client.connect(address); writefln("Where's my error?"); } catch (SocketException) writefln("Success"); } --- Testcase succeeds on Windows, but not Linux, using 2.028 and CentOS 5.3. Most likely, incorrect size of the sockaddr_in struct or something. -[Unknown]
Comment #3 by bugs-d — 2009-04-15T21:03:36Z
Created attachment 324 Set sin_family properly. Pruning down some C-style socket code, I determined that sin_family was the deciding factor on this behavior. Unfortunately, it is unclear to me why this would've regressed from 2.026 (since sin_family has never been set?) Graham, you can work around this issue and verify the fix by recompiling phobos or by writing a subclass for InternetAddress, e.g.: --- import std.c.linux.socket, core.sys.posix.sys.socket; import std.socket; class MyInternetAddress: InternetAddress { this(string addr, ushort port) { sin.sin_family = AddressFamily.INET; super(addr, port); } this(uint addr, ushort port) { sin.sin_family = AddressFamily.INET; super(addr, port); } this(ushort port) { sin.sin_family = AddressFamily.INET; super(port); } } --- If you could verify this fixes your issue, it would be appreciated. Thanks, -[Unknown]
Comment #4 by graham.stjack — 2009-04-16T20:00:48Z
It did indeed fix the issue. My (improved) test code now works in 2.026 and 2.028 when I use the workaround.
Comment #5 by foysavas — 2009-12-24T19:48:56Z
I can confirm this patch applying cleanly to the latest Phobos. Can we get this in for the next DMD release? It's no exaggeration to say that working sockets to some are both their bread and butter.
Comment #6 by denis.tomilin — 2010-02-05T15:46:27Z
*** Issue 3649 has been marked as a duplicate of this issue. ***
Comment #7 by aifgi90 — 2010-02-14T07:18:56Z
Created attachment 567 patch for std.socket Patch for std.socket
Comment #8 by rsinfu — 2010-05-23T01:34:23Z
Fixed in svn r1543. Thanks for the patches!
Comment #9 by sohgo — 2010-05-23T02:43:15Z
Phobos1 has the same problem. I am happy that this fix will be applied to the phobos1 too. Thanks.
Comment #10 by sohgo — 2010-05-23T22:28:02Z
I have looked at the Changeset 1548. Thanks for applying this fix to the phobos1. BTW, Issue 3489 is also a same report of this issue I think. So you can close the Issue 3489 too. Thank you.
Comment #11 by rsinfu — 2010-05-23T23:29:58Z
(In reply to comment #10) > BTW, Issue 3489 is also a same report of this issue I think. > So you can close the Issue 3489 too. I see. Thank you for pointing it out to me. :D