File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ module Network.Socket
141
141
, withFdSocket
142
142
, unsafeFdSocket
143
143
, touchSocket
144
+ , socketToFd
144
145
, fdSocket
145
146
, mkSocket
146
147
, socketToHandle
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ module Network.Socket.Types (
14
14
, withFdSocket
15
15
, unsafeFdSocket
16
16
, touchSocket
17
+ , socketToFd
17
18
, fdSocket
18
19
, mkSocket
19
20
, invalidateSocket
@@ -166,6 +167,18 @@ withFdSocket (Socket ref _) f = do
166
167
touch ref
167
168
return r
168
169
170
+ -- | Socket is closed and a duplicated file descriptor is returned.
171
+ socketToFd :: Socket -> IO CInt
172
+ socketToFd s = do
173
+ fd <- unsafeFdSocket s
174
+ -- FIXME: throw error no if -1
175
+ fd2 <- c_dup fd
176
+ close s
177
+ return fd2
178
+
179
+ foreign import ccall unsafe " dup"
180
+ c_dup :: CInt -> IO CInt
181
+
169
182
-- | Creating a socket from a file descriptor.
170
183
mkSocket :: CInt -> IO Socket
171
184
mkSocket fd = do
You can’t perform that action at this time.
0 commit comments