@@ -78,7 +78,7 @@ bitflags!(
78
78
/// Create an endpoint for communication
79
79
///
80
80
/// [Further reading](http://man7.org/linux/man-pages/man2/socket.2.html)
81
- pub fn socket ( domain : AddressFamily , ty : SockType , flags : SockFlag ) -> Result < Fd > {
81
+ pub fn socket ( domain : AddressFamily , ty : SockType , flags : SockFlag ) -> Result < RawFd > {
82
82
let mut ty = ty as c_int ;
83
83
let feat_atomic = features:: socket_atomic_cloexec ( ) ;
84
84
@@ -109,15 +109,15 @@ pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<Fd
109
109
/// Listen for connections on a socket
110
110
///
111
111
/// [Further reading](http://man7.org/linux/man-pages/man2/listen.2.html)
112
- pub fn listen ( sockfd : Fd , backlog : usize ) -> Result < ( ) > {
112
+ pub fn listen ( sockfd : RawFd , backlog : usize ) -> Result < ( ) > {
113
113
let res = unsafe { ffi:: listen ( sockfd, backlog as c_int ) } ;
114
114
from_ffi ( res)
115
115
}
116
116
117
117
/// Bind a name to a socket
118
118
///
119
119
/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html)
120
- pub fn bind ( fd : Fd , addr : & SockAddr ) -> Result < ( ) > {
120
+ pub fn bind ( fd : RawFd , addr : & SockAddr ) -> Result < ( ) > {
121
121
let res = unsafe {
122
122
let ( ptr, len) = addr. as_ffi_pair ( ) ;
123
123
ffi:: bind ( fd, ptr, len)
@@ -129,7 +129,7 @@ pub fn bind(fd: Fd, addr: &SockAddr) -> Result<()> {
129
129
/// Accept a connection on a socket
130
130
///
131
131
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
132
- pub fn accept ( sockfd : Fd ) -> Result < Fd > {
132
+ pub fn accept ( sockfd : RawFd ) -> Result < RawFd > {
133
133
let res = unsafe { ffi:: accept ( sockfd, ptr:: null_mut ( ) , ptr:: null_mut ( ) ) } ;
134
134
135
135
if res < 0 {
@@ -143,7 +143,7 @@ pub fn accept(sockfd: Fd) -> Result<Fd> {
143
143
///
144
144
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
145
145
#[ cfg( not( any( target_os = "macos" , target_os = "ios" , target_os = "android" ) ) ) ]
146
- pub fn accept4 ( sockfd : Fd , flags : SockFlag ) -> Result < Fd > {
146
+ pub fn accept4 ( sockfd : RawFd , flags : SockFlag ) -> Result < RawFd > {
147
147
use libc:: sockaddr;
148
148
149
149
type F = unsafe extern "C" fn ( c_int , * mut sockaddr , * mut socklen_t , c_int ) -> c_int ;
@@ -173,12 +173,12 @@ pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
173
173
///
174
174
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
175
175
#[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "android" ) ) ]
176
- pub fn accept4 ( sockfd : Fd , flags : SockFlag ) -> Result < Fd > {
176
+ pub fn accept4 ( sockfd : RawFd , flags : SockFlag ) -> Result < RawFd > {
177
177
accept4_polyfill ( sockfd, flags)
178
178
}
179
179
180
180
#[ inline]
181
- fn accept4_polyfill ( sockfd : Fd , flags : SockFlag ) -> Result < Fd > {
181
+ fn accept4_polyfill ( sockfd : RawFd , flags : SockFlag ) -> Result < RawFd > {
182
182
let res = unsafe { ffi:: accept ( sockfd, ptr:: null_mut ( ) , ptr:: null_mut ( ) ) } ;
183
183
184
184
if res < 0 {
@@ -199,7 +199,7 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
199
199
/// Initiate a connection on a socket
200
200
///
201
201
/// [Further reading](http://man7.org/linux/man-pages/man2/connect.2.html)
202
- pub fn connect ( fd : Fd , addr : & SockAddr ) -> Result < ( ) > {
202
+ pub fn connect ( fd : RawFd , addr : & SockAddr ) -> Result < ( ) > {
203
203
let res = unsafe {
204
204
let ( ptr, len) = addr. as_ffi_pair ( ) ;
205
205
ffi:: connect ( fd, ptr, len)
@@ -212,7 +212,7 @@ pub fn connect(fd: Fd, addr: &SockAddr) -> Result<()> {
212
212
/// the number of bytes read and the socket address of the sender.
213
213
///
214
214
/// [Further reading](http://man7.org/linux/man-pages/man2/recvmsg.2.html)
215
- pub fn recvfrom ( sockfd : Fd , buf : & mut [ u8 ] ) -> Result < ( usize , SockAddr ) > {
215
+ pub fn recvfrom ( sockfd : RawFd , buf : & mut [ u8 ] ) -> Result < ( usize , SockAddr ) > {
216
216
unsafe {
217
217
let addr: sockaddr_storage = mem:: zeroed ( ) ;
218
218
let mut len = mem:: size_of :: < sockaddr_storage > ( ) as socklen_t ;
@@ -234,7 +234,7 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
234
234
}
235
235
}
236
236
237
- pub fn sendto ( fd : Fd , buf : & [ u8 ] , addr : & SockAddr , flags : SockMessageFlags ) -> Result < usize > {
237
+ pub fn sendto ( fd : RawFd , buf : & [ u8 ] , addr : & SockAddr , flags : SockMessageFlags ) -> Result < usize > {
238
238
let ret = unsafe {
239
239
let ( ptr, len) = addr. as_ffi_pair ( ) ;
240
240
ffi:: sendto ( fd, buf. as_ptr ( ) as * const c_void , buf. len ( ) as size_t , flags, ptr, len)
@@ -284,30 +284,30 @@ pub trait SockOpt : Copy + fmt::Debug {
284
284
type Set ;
285
285
286
286
#[ doc( hidden) ]
287
- fn get ( & self , fd : Fd , level : c_int ) -> Result < Self :: Get > ;
287
+ fn get ( & self , fd : RawFd , level : c_int ) -> Result < Self :: Get > ;
288
288
289
289
#[ doc( hidden) ]
290
- fn set ( & self , fd : Fd , level : c_int , val : Self :: Set ) -> Result < ( ) > ;
290
+ fn set ( & self , fd : RawFd , level : c_int , val : Self :: Set ) -> Result < ( ) > ;
291
291
}
292
292
293
293
/// Get the current value for the requested socket option
294
294
///
295
295
/// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html)
296
- pub fn getsockopt < O : SockOpt > ( fd : Fd , level : SockLevel , opt : O ) -> Result < O :: Get > {
296
+ pub fn getsockopt < O : SockOpt > ( fd : RawFd , level : SockLevel , opt : O ) -> Result < O :: Get > {
297
297
opt. get ( fd, level as c_int )
298
298
}
299
299
300
300
/// Sets the value for the requested socket option
301
301
///
302
302
/// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html)
303
- pub fn setsockopt < O : SockOpt > ( fd : Fd , level : SockLevel , opt : O , val : O :: Set ) -> Result < ( ) > {
303
+ pub fn setsockopt < O : SockOpt > ( fd : RawFd , level : SockLevel , opt : O , val : O :: Set ) -> Result < ( ) > {
304
304
opt. set ( fd, level as c_int , val)
305
305
}
306
306
307
307
/// Get the address of the peer connected to the socket `fd`.
308
308
///
309
309
/// [Further reading](http://man7.org/linux/man-pages/man2/getpeername.2.html)
310
- pub fn getpeername ( fd : Fd ) -> Result < SockAddr > {
310
+ pub fn getpeername ( fd : RawFd ) -> Result < SockAddr > {
311
311
unsafe {
312
312
let addr: sockaddr_storage = mem:: uninitialized ( ) ;
313
313
let mut len = mem:: size_of :: < sockaddr_storage > ( ) as socklen_t ;
@@ -325,7 +325,7 @@ pub fn getpeername(fd: Fd) -> Result<SockAddr> {
325
325
/// Get the current address to which the socket `fd` is bound.
326
326
///
327
327
/// [Further reading](http://man7.org/linux/man-pages/man2/getsockname.2.html)
328
- pub fn getsockname ( fd : Fd ) -> Result < SockAddr > {
328
+ pub fn getsockname ( fd : RawFd ) -> Result < SockAddr > {
329
329
unsafe {
330
330
let addr: sockaddr_storage = mem:: uninitialized ( ) ;
331
331
let mut len = mem:: size_of :: < sockaddr_storage > ( ) as socklen_t ;
0 commit comments