Ticket #1699: network_aus.dpatch

File network_aus.dpatch, 10.5 KB (added by kolmodin@…, 7 years ago)

Darcs patch for abstract unix sockets

Line 
1
2New patches:
3
4[Fix abstract unix sockets
5Lennart Kolmodin <kolmodin@dtek.chalmers.se>**20070916084418
6 Abstract Unix Socket paths begin with a zero, are not zero terminated and
7 needs accurate socklen calculation. Thus this patch, on linux:
8 
9 * Calculates the exact size of sockaddr.
10 * Pokes sockaddr correctly wrt aus.
11 
12 Also, due to much more socklen usage:
13 * Switch Network.Socket to use CSockLen instead of CInt.
14 * Cleanup surrounding code.
15] {
16hunk ./Network/Socket.hsc 204
17-import Foreign.Marshal.Array ( peekArray, pokeArray0 )
18+import Foreign.Marshal.Array ( peekArray, pokeArray, pokeArray0 )
19hunk ./Network/Socket.hsc 230
20+type CSockLen       = #type socklen_t
21hunk ./Network/Socket.hsc 479
22+pokeSockAddr :: Ptr SockAddr -> SockAddr -> IO ()
23hunk ./Network/Socket.hsc 487
24-       pokeArray0 0 ((#ptr struct sockaddr_un, sun_path) p) pathC
25+            poker = case path of
26+#if linux_TARGET_OS
27+                        -- leading zero indicates abstract unix socket
28+                        ('\0':_) -> pokeArray -- they should not be zero
29+                                              -- terminated
30+#endif
31+                        _        -> pokeArray0 0
32+       poker ((#ptr struct sockaddr_un, sun_path) p) pathC
33hunk ./Network/Socket.hsc 515
34-peekSockAddr :: Ptr SockAddr -> IO SockAddr
35-
36-peekSockAddr p = do
37+-- we need the length of the socket address to correctly read unix sockets
38+peekSockAddr :: Ptr SockAddr -> CSockLen -> IO SockAddr
39+peekSockAddr p len = do
40hunk ./Network/Socket.hsc 522
41-               str <- peekCString ((#ptr struct sockaddr_un, sun_path) p)
42+                let str_len = fromIntegral len - #offset struct sockaddr_un, sun_path
43+               str <- peekCStringLen ((#ptr struct sockaddr_un, sun_path) p, str_len)
44hunk ./Network/Socket.hsc 554
45+sizeOfSockAddr :: SockAddr -> CSockLen
46hunk ./Network/Socket.hsc 556
47-sizeOfSockAddr (SockAddrUnix _)   = #const sizeof(struct sockaddr_un)
48+sizeOfSockAddr (SockAddrUnix path)   =
49+    case path of
50+#if linux_TARGET_OS
51+        -- abstract unix sockets doesn't end with a zero
52+        ('\0':_) ->     (fromIntegral $ length path) + #offset struct sockaddr_un, sun_path
53+#endif
54+        -- regular unix sockets do
55+        _        -> 1 + (fromIntegral $ length path) + #offset struct sockaddr_un, sun_path
56hunk ./Network/Socket.hsc 570
57-withSockAddr :: SockAddr -> (Ptr SockAddr -> Int -> IO a) -> IO a
58+withSockAddr :: SockAddr -> (Ptr SockAddr -> CSockLen -> IO a) -> IO a
59hunk ./Network/Socket.hsc 573
60- allocaBytes sz $ \p -> pokeSockAddr p addr >> f (castPtr p) sz
61+ allocaBytes (fromIntegral sz) $ \p -> pokeSockAddr p addr >> f (castPtr p) sz
62hunk ./Network/Socket.hsc 575
63-withNewSockAddr :: Family -> (Ptr SockAddr -> Int -> IO a) -> IO a
64+withNewSockAddr :: Family -> (Ptr SockAddr -> CSockLen -> IO a) -> IO a
65hunk ./Network/Socket.hsc 578
66- allocaBytes sz $ \ptr -> f ptr sz
67+ allocaBytes (fromIntegral sz) $ \ptr -> f ptr sz
68hunk ./Network/Socket.hsc 671
69-   status <- throwSocketErrorIfMinus1Retry "bind" $ c_bind s p_addr (fromIntegral sz)
70+   status <- throwSocketErrorIfMinus1Retry "bind" $ c_bind s p_addr sz
71hunk ./Network/Socket.hsc 702
72-                  r <- c_connect s p_addr (fromIntegral sz)
73+                  r <- c_connect s p_addr sz
74hunk ./Network/Socket.hsc 717
75-                          r <- c_connect s p_addr (fromIntegral sz)
76+                          r <- c_connect s p_addr sz
77hunk ./Network/Socket.hsc 787
78-     let sz = sizeOfSockAddr_Family family
79-     allocaBytes sz $ \ sockaddr -> do
80+     withNewSockAddr family $ \sockaddr sz -> do
81hunk ./Network/Socket.hsc 814
82-     addr <- peekSockAddr sockaddr
83+     addr <- peek ptr_len >>= peekSockAddr sockaddr
84hunk ./Network/Socket.hsc 854
85-                       p_addr (fromIntegral sz)
86+                       p_addr sz
87hunk ./Network/Socket.hsc 868
88-      alloca $ \ptr_len -> do
89-       poke ptr_len (fromIntegral sz)
90+      with sz $ \ptr_len -> do
91hunk ./Network/Socket.hsc 888
92-                  peekSockAddr ptr_addr
93+                  peek ptr_len >>= peekSockAddr ptr_addr
94hunk ./Network/Socket.hsc 971
95-   with (fromIntegral sz) $ \int_star -> do
96-   throwSocketErrorIfMinus1Retry "getPeerName" $ c_getpeername s ptr int_star
97-   sz <- peek int_star
98-   peekSockAddr ptr
99-   
100+   with sz $ \ptr_sz -> do
101+   throwSocketErrorIfMinus1Retry "getPeerName" $ c_getpeername s ptr ptr_sz
102+   peek ptr_sz >>= peekSockAddr ptr
103+
104hunk ./Network/Socket.hsc 978
105-   with (fromIntegral sz) $ \int_star -> do
106-   throwSocketErrorIfMinus1Retry "getSocketName" $ c_getsockname s ptr int_star
107-   peekSockAddr ptr
108+   with sz $ \ptr_sz -> do
109+   throwSocketErrorIfMinus1Retry "getSocketName" $ c_getsockname s ptr ptr_sz
110+   peek ptr_sz >>= peekSockAddr ptr
111hunk ./Network/Socket.hsc 2191
112-        ai_addr <- (#peek struct addrinfo, ai_addr) p >>= peekSockAddr
113+        ai_addrlen <- (#peek struct addrinfo, ai_addrlen) p
114+        ai_addr <- (#peek struct addrinfo, ai_addr) p >>= peekSockAddr ai_addrlen
115hunk ./Network/Socket.hsc 2209
116-    poke p (AddrInfo flags family socketType protocol _ _) = do
117+    poke p (AddrInfo flags family socketType protocol addr _) = do
118hunk ./Network/Socket.hsc 2214
119+        let sz = fromIntegral (sizeOfSockAddr addr)
120+        (#poke struct addrinfo, ai_addrlen) p (sz :: CSize)
121hunk ./Network/Socket.hsc 2219
122-        (#poke struct addrinfo, ai_addrlen) p (0::CSize)
123hunk ./Network/Socket.hsc 2437
124-        ret <- c_getnameinfo ptr_addr (fromIntegral sz) c_host c_hostlen
125+        ret <- c_getnameinfo ptr_addr sz c_host c_hostlen
126hunk ./Network/Socket.hsc 2452
127-    c_getnameinfo :: Ptr SockAddr -> CInt{-CSockLen???-} -> CString -> CSize -> CString
128+    c_getnameinfo :: Ptr SockAddr -> CSockLen -> CString -> CSize -> CString
129hunk ./Network/Socket.hsc 2520
130-  c_bind :: CInt -> Ptr SockAddr -> CInt{-CSockLen???-} -> IO CInt
131+  c_bind :: CInt -> Ptr SockAddr -> CSockLen -> IO CInt
132hunk ./Network/Socket.hsc 2522
133-  c_connect :: CInt -> Ptr SockAddr -> CInt{-CSockLen???-} -> IO CInt
134+  c_connect :: CInt -> Ptr SockAddr -> CSockLen -> IO CInt
135hunk ./Network/Socket.hsc 2524
136-  c_accept :: CInt -> Ptr SockAddr -> Ptr CInt{-CSockLen???-} -> IO CInt
137+  c_accept :: CInt -> Ptr SockAddr -> Ptr CSockLen -> IO CInt
138hunk ./Network/Socket.hsc 2526
139-  c_accept_safe :: CInt -> Ptr SockAddr -> Ptr CInt{-CSockLen???-} -> IO CInt
140+  c_accept_safe :: CInt -> Ptr SockAddr -> Ptr CSockLen -> IO CInt
141hunk ./Network/Socket.hsc 2537
142-  c_sendto :: CInt -> Ptr a -> CSize -> CInt -> Ptr SockAddr -> CInt -> IO CInt
143+  c_sendto :: CInt -> Ptr a -> CSize -> CInt -> Ptr SockAddr -> CSockLen -> IO CInt
144hunk ./Network/Socket.hsc 2541
145-  c_recvfrom :: CInt -> Ptr a -> CSize -> CInt -> Ptr SockAddr -> Ptr CInt -> IO CInt
146+  c_recvfrom :: CInt -> Ptr a -> CSize -> CInt -> Ptr SockAddr -> Ptr CSockLen -> IO CInt
147hunk ./Network/Socket.hsc 2543
148-  c_getpeername :: CInt -> Ptr SockAddr -> Ptr CInt -> IO CInt
149+  c_getpeername :: CInt -> Ptr SockAddr -> Ptr CSockLen -> IO CInt
150hunk ./Network/Socket.hsc 2545
151-  c_getsockname :: CInt -> Ptr SockAddr -> Ptr CInt -> IO CInt
152+  c_getsockname :: CInt -> Ptr SockAddr -> Ptr CSockLen -> IO CInt
153}
154
155Context:
156
157[Follow openFd -> fdToHandle' rename
158Ian Lynagh <igloo@earth.li>**20070722184622]
159[Sleep for a second before trying to connect in the net001 test
160Ian Lynagh <igloo@earth.li>**20070717122449
161 With just a yield, in threaded1/2 ways the client was sometimes trying
162 to connect before the server was listening.
163]
164[Quieten build on OS X.
165Bryan O'Sullivan <bos@serpentine.com>**20070627213703]
166[Fix use of autoconf HAVE_DECL_* macros.
167Bryan O'Sullivan <bos@serpentine.com>**20070627213617
168 It turns out that the macros are always defined, unlike most others.
169]
170[Make IPv6 address handling more portable and robust.
171Bryan O'Sullivan <bos@serpentine.com>**20070627182816
172 
173 1.  No longer rely on the in6_addr structure's s6_addr32 field, which
174     is not available on many platforms.  Use s6_addr instead.
175 
176 2.  Add a number of AI_* flags that are required by RFC 3493.  Not all
177     of these flags are implemented on all systems, but on systems
178     where they *are* implemented, we get runtime exceptions if we
179     don't make them available.
180 
181 3.  To let users check whether a particular AI_* flag is implemented,
182     we introduce the addrInfoFlagImplemented function.
183 
184 4.  Fix the autoconf macro used to check for AI_* flag availability.
185     The previous check wasn't portable, and caused flags to appear not
186     to be present when they really were.
187]
188[FIX net001 (Windows): get some calling conventions right
189Simon Marlow <simonmar@microsoft.com>**20070703082831]
190[Fix further build problems when IPv6 isn't available
191Simon Marlow <simonmar@microsoft.com>**20070604105407]
192[Try a hopefully more portable test for RFC 3493 API compatibility.
193Bryan O'Sullivan <bos@serpentine.com>**20070602050225]
194[Fix build failure if IPv6 is not available.
195Bryan O'Sullivan <bos@serpentine.com>**20070601160943]
196[Fixed support for platforms with IPv6 but no AI_ADDRCONFIG
197Michael D. Adams <t-madams@microsoft.com>**20070604153642]
198[--configure-option and --ghc-option are now provided by Cabal
199Ross Paterson <ross@soi.city.ac.uk>**20070604115612]
200[Invoke the preprocessor portably.
201Bryan O'Sullivan <bos@serpentine.com>**20070408171912]
202[Add IPv6 support to Network.
203Bryan O'Sullivan <bos@serpentine.com>**20070404223751
204 
205 The public API remains unchanged; it can now transparently handle IPv6
206 addresses and sockets.
207]
208[Add IPv6 support to Network.Socket.
209Bryan O'Sullivan <bos@serpentine.com>**20070404222036
210 
211 The only public API changes are to Network.Socket, which has the following
212 exported names added (no existing names have been removed):
213 
214     -- IPv6 address components
215     HostAddress6
216     FlowInfo
217     ScopeID
218 
219     -- Name -> address lookup
220     getAddrInfo
221     AddrInfo
222     AddrInfoFlag
223     defaultHints
224 
225     -- Address -> name lookup
226     getNameInfo
227     NameInfoFlag
228 
229 The SockAddr type acquires a new branch, SockAddr6.  (This could cause
230 new "non-exhaustive matches" warnings when compiling pre-existing client
231 code that pattern-matches on SockAddr values.  However, it will not
232 cause runtime pattern failure errors in clients using the pre-existing
233 IPv4 entry points, as they will never see IPv6 addresses.)
234 
235 This change moves a few type names from Network.BSD to Network.Socket:
236 
237     HostName
238     ServiceName
239 
240 These names are still re-exported from Network.BSD, so pre-existing code
241 should not be affected.
242]
243[Remove Makefile and package.conf.in (used in the old GHC build system)
244Ian Lynagh <igloo@earth.li>**20070524145815]
245[add includes: field
246Simon Marlow <simonmar@microsoft.com>**20070517095001]
247[TAG GHC 6.6.1 release
248Ian Lynagh <igloo@earth.li>**20070428195851]
249Patch bundle hash:
250d612884aa9992581596e736e03be3cfe42745c63