Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris | 5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "io" | 10 "io" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 } | 69 } |
70 | 70 |
71 func (fd *netFD) connect(la, ra syscall.Sockaddr) error { | 71 func (fd *netFD) connect(la, ra syscall.Sockaddr) error { |
72 // Do not need to call fd.writeLock here, | 72 // Do not need to call fd.writeLock here, |
73 // because fd is not yet accessible to user, | 73 // because fd is not yet accessible to user, |
74 // so no concurrent operations are possible. | 74 // so no concurrent operations are possible. |
75 if err := fd.pd.PrepareWrite(); err != nil { | 75 if err := fd.pd.PrepareWrite(); err != nil { |
76 return err | 76 return err |
77 } | 77 } |
78 switch err := syscall.Connect(fd.sysfd, ra); err { | 78 switch err := syscall.Connect(fd.sysfd, ra); err { |
79 case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: | |
79 case nil, syscall.EISCONN: | 80 case nil, syscall.EISCONN: |
80 return nil | 81 return nil |
81 case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: | |
jsing
2014/03/25 11:49:41
Nit: This may be more readable with this as the fi
mikio
2014/03/26 02:43:18
Done.
| |
82 case syscall.EINVAL: | 82 case syscall.EINVAL: |
83 // On Solaris we can see EINVAL if the socket has | 83 // On Solaris we can see EINVAL if the socket has |
84 // already been accepted and closed by the server. | 84 // already been accepted and closed by the server. |
85 // Treat this as a successful connection--writes to | 85 // Treat this as a successful connection--writes to |
86 // the socket will see EOF. For details and a test | 86 // the socket will see EOF. For details and a test |
87 // case in C see http://golang.org/issue/6828. | 87 // case in C see http://golang.org/issue/6828. |
88 if runtime.GOOS == "solaris" { | 88 if runtime.GOOS == "solaris" { |
89 return nil | 89 return nil |
90 } | 90 } |
91 fallthrough | 91 fallthrough |
92 default: | 92 default: |
93 return err | 93 return err |
94 } | 94 } |
95 for { | 95 for { |
96 // Performing multiple connect system calls on a | 96 // Performing multiple connect system calls on a |
97 // non-blocking socket under Unix variants does not | 97 // non-blocking socket under Unix variants does not |
98 // necessarily result in earlier errors being | 98 // necessarily result in earlier errors being |
99 // returned. Instead, once runtime-integrated network | 99 // returned. Instead, once runtime-integrated network |
100 // poller tells us that the socket is ready, get the | 100 // poller tells us that the socket is ready, get the |
101 // SO_ERROR socket option to see if the connection | 101 // SO_ERROR socket option to see if the connection |
102 // succeeded or failed. See issue 7474 for further | 102 // succeeded or failed. See issue 7474 for further |
103 // details. | 103 // details. |
104 if err := fd.pd.WaitWrite(); err != nil { | 104 if err := fd.pd.WaitWrite(); err != nil { |
105 return err | 105 return err |
106 } | 106 } |
107 nerr, err := syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR) | 107 nerr, err := syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR) |
108 if err != nil { | 108 if err != nil { |
109 return err | 109 return err |
110 } | 110 } |
111 » » switch err = syscall.Errno(nerr); err { | 111 » » switch err := syscall.Errno(nerr); err { |
jsing
2014/03/25 11:49:41
You should be able to use := here.
mikio
2014/03/26 02:43:18
Done.
| |
112 » » case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: | |
112 case syscall.Errno(0), syscall.EISCONN: | 113 case syscall.Errno(0), syscall.EISCONN: |
113 return nil | 114 return nil |
114 case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: | |
jsing
2014/03/25 11:49:41
Same here.
mikio
2014/03/26 02:43:18
Done.
| |
115 default: | 115 default: |
116 return err | 116 return err |
117 } | 117 } |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 func (fd *netFD) destroy() { | 121 func (fd *netFD) destroy() { |
122 // Poller may want to unregister fd in readiness notification mechanism, | 122 // Poller may want to unregister fd in readiness notification mechanism, |
123 // so this must be executed before closesocket. | 123 // so this must be executed before closesocket. |
124 fd.pd.Close() | 124 fd.pd.Close() |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 func closesocket(s int) error { | 501 func closesocket(s int) error { |
502 return syscall.Close(s) | 502 return syscall.Close(s) |
503 } | 503 } |
504 | 504 |
505 func skipRawSocketTests() (skip bool, skipmsg string, err error) { | 505 func skipRawSocketTests() (skip bool, skipmsg string, err error) { |
506 if os.Getuid() != 0 { | 506 if os.Getuid() != 0 { |
507 return true, "skipping test; must be root", nil | 507 return true, "skipping test; must be root", nil |
508 } | 508 } |
509 return false, "", nil | 509 return false, "", nil |
510 } | 510 } |
LEFT | RIGHT |