@@ -859,35 +859,35 @@ impl SockAddr {
859
859
}
860
860
}
861
861
862
- pub ( crate ) type Socket = c_int ;
862
+ pub ( crate ) type RawSocket = c_int ;
863
863
864
- pub ( crate ) unsafe fn socket_from_raw ( socket : Socket ) -> crate :: socket:: Inner {
864
+ pub ( crate ) unsafe fn socket_from_raw ( socket : RawSocket ) -> crate :: socket:: Inner {
865
865
crate :: socket:: Inner :: from_raw_fd ( socket)
866
866
}
867
867
868
- pub ( crate ) fn socket_as_raw ( socket : & crate :: socket:: Inner ) -> Socket {
868
+ pub ( crate ) fn socket_as_raw ( socket : & crate :: socket:: Inner ) -> RawSocket {
869
869
socket. as_raw_fd ( )
870
870
}
871
871
872
- pub ( crate ) fn socket_into_raw ( socket : crate :: socket:: Inner ) -> Socket {
872
+ pub ( crate ) fn socket_into_raw ( socket : crate :: socket:: Inner ) -> RawSocket {
873
873
socket. into_raw_fd ( )
874
874
}
875
875
876
- pub ( crate ) fn socket ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < Socket > {
876
+ pub ( crate ) fn socket ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < RawSocket > {
877
877
syscall ! ( socket( family, ty, protocol) )
878
878
}
879
879
880
880
#[ cfg( all( feature = "all" , unix) ) ]
881
- pub ( crate ) fn socketpair ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < [ Socket ; 2 ] > {
881
+ pub ( crate ) fn socketpair ( family : c_int , ty : c_int , protocol : c_int ) -> io:: Result < [ RawSocket ; 2 ] > {
882
882
let mut fds = [ 0 , 0 ] ;
883
883
syscall ! ( socketpair( family, ty, protocol, fds. as_mut_ptr( ) ) ) . map ( |_| fds)
884
884
}
885
885
886
- pub ( crate ) fn bind ( fd : Socket , addr : & SockAddr ) -> io:: Result < ( ) > {
886
+ pub ( crate ) fn bind ( fd : RawSocket , addr : & SockAddr ) -> io:: Result < ( ) > {
887
887
syscall ! ( bind( fd, addr. as_ptr( ) . cast:: <sockaddr>( ) , addr. len( ) as _) ) . map ( |_| ( ) )
888
888
}
889
889
890
- pub ( crate ) fn connect ( fd : Socket , addr : & SockAddr ) -> io:: Result < ( ) > {
890
+ pub ( crate ) fn connect ( fd : RawSocket , addr : & SockAddr ) -> io:: Result < ( ) > {
891
891
syscall ! ( connect( fd, addr. as_ptr( ) . cast:: <sockaddr>( ) , addr. len( ) ) ) . map ( |_| ( ) )
892
892
}
893
893
@@ -933,46 +933,46 @@ pub(crate) fn poll_connect(socket: &crate::Socket, timeout: Duration) -> io::Res
933
933
}
934
934
}
935
935
936
- pub ( crate ) fn listen ( fd : Socket , backlog : c_int ) -> io:: Result < ( ) > {
936
+ pub ( crate ) fn listen ( fd : RawSocket , backlog : c_int ) -> io:: Result < ( ) > {
937
937
syscall ! ( listen( fd, backlog) ) . map ( |_| ( ) )
938
938
}
939
939
940
- pub ( crate ) fn accept ( fd : Socket ) -> io:: Result < ( Socket , SockAddr ) > {
940
+ pub ( crate ) fn accept ( fd : RawSocket ) -> io:: Result < ( RawSocket , SockAddr ) > {
941
941
// Safety: `accept` initialises the `SockAddr` for us.
942
942
unsafe { SockAddr :: try_init ( |storage, len| syscall ! ( accept( fd, storage. cast( ) , len) ) ) }
943
943
}
944
944
945
- pub ( crate ) fn getsockname ( fd : Socket ) -> io:: Result < SockAddr > {
945
+ pub ( crate ) fn getsockname ( fd : RawSocket ) -> io:: Result < SockAddr > {
946
946
// Safety: `accept` initialises the `SockAddr` for us.
947
947
unsafe { SockAddr :: try_init ( |storage, len| syscall ! ( getsockname( fd, storage. cast( ) , len) ) ) }
948
948
. map ( |( _, addr) | addr)
949
949
}
950
950
951
- pub ( crate ) fn getpeername ( fd : Socket ) -> io:: Result < SockAddr > {
951
+ pub ( crate ) fn getpeername ( fd : RawSocket ) -> io:: Result < SockAddr > {
952
952
// Safety: `accept` initialises the `SockAddr` for us.
953
953
unsafe { SockAddr :: try_init ( |storage, len| syscall ! ( getpeername( fd, storage. cast( ) , len) ) ) }
954
954
. map ( |( _, addr) | addr)
955
955
}
956
956
957
- pub ( crate ) fn try_clone ( fd : Socket ) -> io:: Result < Socket > {
957
+ pub ( crate ) fn try_clone ( fd : RawSocket ) -> io:: Result < RawSocket > {
958
958
syscall ! ( fcntl( fd, libc:: F_DUPFD_CLOEXEC , 0 ) )
959
959
}
960
960
961
961
#[ cfg( all( feature = "all" , unix, not( target_os = "vita" ) ) ) ]
962
- pub ( crate ) fn nonblocking ( fd : Socket ) -> io:: Result < bool > {
962
+ pub ( crate ) fn nonblocking ( fd : RawSocket ) -> io:: Result < bool > {
963
963
let file_status_flags = fcntl_get ( fd, libc:: F_GETFL ) ?;
964
964
Ok ( ( file_status_flags & libc:: O_NONBLOCK ) != 0 )
965
965
}
966
966
967
967
#[ cfg( all( feature = "all" , target_os = "vita" ) ) ]
968
- pub ( crate ) fn nonblocking ( fd : Socket ) -> io:: Result < bool > {
968
+ pub ( crate ) fn nonblocking ( fd : RawSocket ) -> io:: Result < bool > {
969
969
unsafe {
970
970
getsockopt :: < Bool > ( fd, libc:: SOL_SOCKET , libc:: SO_NONBLOCK ) . map ( |non_block| non_block != 0 )
971
971
}
972
972
}
973
973
974
974
#[ cfg( not( target_os = "vita" ) ) ]
975
- pub ( crate ) fn set_nonblocking ( fd : Socket , nonblocking : bool ) -> io:: Result < ( ) > {
975
+ pub ( crate ) fn set_nonblocking ( fd : RawSocket , nonblocking : bool ) -> io:: Result < ( ) > {
976
976
if nonblocking {
977
977
fcntl_add ( fd, libc:: F_GETFL , libc:: F_SETFL , libc:: O_NONBLOCK )
978
978
} else {
@@ -981,7 +981,7 @@ pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
981
981
}
982
982
983
983
#[ cfg( target_os = "vita" ) ]
984
- pub ( crate ) fn set_nonblocking ( fd : Socket , nonblocking : bool ) -> io:: Result < ( ) > {
984
+ pub ( crate ) fn set_nonblocking ( fd : RawSocket , nonblocking : bool ) -> io:: Result < ( ) > {
985
985
unsafe {
986
986
setsockopt (
987
987
fd,
@@ -992,7 +992,7 @@ pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
992
992
}
993
993
}
994
994
995
- pub ( crate ) fn shutdown ( fd : Socket , how : Shutdown ) -> io:: Result < ( ) > {
995
+ pub ( crate ) fn shutdown ( fd : RawSocket , how : Shutdown ) -> io:: Result < ( ) > {
996
996
let how = match how {
997
997
Shutdown :: Write => libc:: SHUT_WR ,
998
998
Shutdown :: Read => libc:: SHUT_RD ,
@@ -1001,7 +1001,7 @@ pub(crate) fn shutdown(fd: Socket, how: Shutdown) -> io::Result<()> {
1001
1001
syscall ! ( shutdown( fd, how) ) . map ( |_| ( ) )
1002
1002
}
1003
1003
1004
- pub ( crate ) fn recv ( fd : Socket , buf : & mut [ MaybeUninit < u8 > ] , flags : c_int ) -> io:: Result < usize > {
1004
+ pub ( crate ) fn recv ( fd : RawSocket , buf : & mut [ MaybeUninit < u8 > ] , flags : c_int ) -> io:: Result < usize > {
1005
1005
syscall ! ( recv(
1006
1006
fd,
1007
1007
buf. as_mut_ptr( ) . cast( ) ,
@@ -1012,7 +1012,7 @@ pub(crate) fn recv(fd: Socket, buf: &mut [MaybeUninit<u8>], flags: c_int) -> io:
1012
1012
}
1013
1013
1014
1014
pub ( crate ) fn recv_from (
1015
- fd : Socket ,
1015
+ fd : RawSocket ,
1016
1016
buf : & mut [ MaybeUninit < u8 > ] ,
1017
1017
flags : c_int ,
1018
1018
) -> io:: Result < ( usize , SockAddr ) > {
@@ -1032,7 +1032,7 @@ pub(crate) fn recv_from(
1032
1032
}
1033
1033
}
1034
1034
1035
- pub ( crate ) fn peek_sender ( fd : Socket ) -> io:: Result < SockAddr > {
1035
+ pub ( crate ) fn peek_sender ( fd : RawSocket ) -> io:: Result < SockAddr > {
1036
1036
// Unix-like platforms simply truncate the returned data, so this implementation is trivial.
1037
1037
// However, for Windows this requires suppressing the `WSAEMSGSIZE` error,
1038
1038
// so that requires a different approach.
@@ -1043,7 +1043,7 @@ pub(crate) fn peek_sender(fd: Socket) -> io::Result<SockAddr> {
1043
1043
1044
1044
#[ cfg( not( target_os = "redox" ) ) ]
1045
1045
pub ( crate ) fn recv_vectored (
1046
- fd : Socket ,
1046
+ fd : RawSocket ,
1047
1047
bufs : & mut [ crate :: MaybeUninitSlice < ' _ > ] ,
1048
1048
flags : c_int ,
1049
1049
) -> io:: Result < ( usize , RecvFlags ) > {
@@ -1054,7 +1054,7 @@ pub(crate) fn recv_vectored(
1054
1054
1055
1055
#[ cfg( not( target_os = "redox" ) ) ]
1056
1056
pub ( crate ) fn recv_from_vectored (
1057
- fd : Socket ,
1057
+ fd : RawSocket ,
1058
1058
bufs : & mut [ crate :: MaybeUninitSlice < ' _ > ] ,
1059
1059
flags : c_int ,
1060
1060
) -> io:: Result < ( usize , RecvFlags , SockAddr ) > {
@@ -1076,14 +1076,14 @@ pub(crate) fn recv_from_vectored(
1076
1076
1077
1077
#[ cfg( not( target_os = "redox" ) ) ]
1078
1078
pub ( crate ) fn recvmsg (
1079
- fd : Socket ,
1079
+ fd : RawSocket ,
1080
1080
msg : & mut MsgHdrMut < ' _ , ' _ , ' _ > ,
1081
1081
flags : c_int ,
1082
1082
) -> io:: Result < usize > {
1083
1083
syscall ! ( recvmsg( fd, & mut msg. inner, flags) ) . map ( |n| n as usize )
1084
1084
}
1085
1085
1086
- pub ( crate ) fn send ( fd : Socket , buf : & [ u8 ] , flags : c_int ) -> io:: Result < usize > {
1086
+ pub ( crate ) fn send ( fd : RawSocket , buf : & [ u8 ] , flags : c_int ) -> io:: Result < usize > {
1087
1087
syscall ! ( send(
1088
1088
fd,
1089
1089
buf. as_ptr( ) . cast( ) ,
@@ -1094,12 +1094,21 @@ pub(crate) fn send(fd: Socket, buf: &[u8], flags: c_int) -> io::Result<usize> {
1094
1094
}
1095
1095
1096
1096
#[ cfg( not( target_os = "redox" ) ) ]
1097
- pub ( crate ) fn send_vectored ( fd : Socket , bufs : & [ IoSlice < ' _ > ] , flags : c_int ) -> io:: Result < usize > {
1097
+ pub ( crate ) fn send_vectored (
1098
+ fd : RawSocket ,
1099
+ bufs : & [ IoSlice < ' _ > ] ,
1100
+ flags : c_int ,
1101
+ ) -> io:: Result < usize > {
1098
1102
let msg = MsgHdr :: new ( ) . with_buffers ( bufs) ;
1099
1103
sendmsg ( fd, & msg, flags)
1100
1104
}
1101
1105
1102
- pub ( crate ) fn send_to ( fd : Socket , buf : & [ u8 ] , addr : & SockAddr , flags : c_int ) -> io:: Result < usize > {
1106
+ pub ( crate ) fn send_to (
1107
+ fd : RawSocket ,
1108
+ buf : & [ u8 ] ,
1109
+ addr : & SockAddr ,
1110
+ flags : c_int ,
1111
+ ) -> io:: Result < usize > {
1103
1112
syscall ! ( sendto(
1104
1113
fd,
1105
1114
buf. as_ptr( ) . cast( ) ,
@@ -1113,7 +1122,7 @@ pub(crate) fn send_to(fd: Socket, buf: &[u8], addr: &SockAddr, flags: c_int) ->
1113
1122
1114
1123
#[ cfg( not( target_os = "redox" ) ) ]
1115
1124
pub ( crate ) fn send_to_vectored (
1116
- fd : Socket ,
1125
+ fd : RawSocket ,
1117
1126
bufs : & [ IoSlice < ' _ > ] ,
1118
1127
addr : & SockAddr ,
1119
1128
flags : c_int ,
@@ -1123,12 +1132,12 @@ pub(crate) fn send_to_vectored(
1123
1132
}
1124
1133
1125
1134
#[ cfg( not( target_os = "redox" ) ) ]
1126
- pub ( crate ) fn sendmsg ( fd : Socket , msg : & MsgHdr < ' _ , ' _ , ' _ > , flags : c_int ) -> io:: Result < usize > {
1135
+ pub ( crate ) fn sendmsg ( fd : RawSocket , msg : & MsgHdr < ' _ , ' _ , ' _ > , flags : c_int ) -> io:: Result < usize > {
1127
1136
syscall ! ( sendmsg( fd, & msg. inner, flags) ) . map ( |n| n as usize )
1128
1137
}
1129
1138
1130
1139
/// Wrapper around `getsockopt` to deal with platform specific timeouts.
1131
- pub ( crate ) fn timeout_opt ( fd : Socket , opt : c_int , val : c_int ) -> io:: Result < Option < Duration > > {
1140
+ pub ( crate ) fn timeout_opt ( fd : RawSocket , opt : c_int , val : c_int ) -> io:: Result < Option < Duration > > {
1132
1141
unsafe { getsockopt ( fd, opt, val) . map ( from_timeval) }
1133
1142
}
1134
1143
@@ -1144,7 +1153,7 @@ const fn from_timeval(duration: libc::timeval) -> Option<Duration> {
1144
1153
1145
1154
/// Wrapper around `setsockopt` to deal with platform specific timeouts.
1146
1155
pub ( crate ) fn set_timeout_opt (
1147
- fd : Socket ,
1156
+ fd : RawSocket ,
1148
1157
opt : c_int ,
1149
1158
val : c_int ,
1150
1159
duration : Option < Duration > ,
@@ -1172,15 +1181,15 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
1172
1181
feature = "all" ,
1173
1182
not( any( target_os = "haiku" , target_os = "openbsd" , target_os = "vita" ) )
1174
1183
) ) ]
1175
- pub ( crate ) fn tcp_keepalive_time ( fd : Socket ) -> io:: Result < Duration > {
1184
+ pub ( crate ) fn tcp_keepalive_time ( fd : RawSocket ) -> io:: Result < Duration > {
1176
1185
unsafe {
1177
1186
getsockopt :: < c_int > ( fd, IPPROTO_TCP , KEEPALIVE_TIME )
1178
1187
. map ( |secs| Duration :: from_secs ( secs as u64 ) )
1179
1188
}
1180
1189
}
1181
1190
1182
1191
#[ allow( unused_variables) ]
1183
- pub ( crate ) fn set_tcp_keepalive ( fd : Socket , keepalive : & TcpKeepalive ) -> io:: Result < ( ) > {
1192
+ pub ( crate ) fn set_tcp_keepalive ( fd : RawSocket , keepalive : & TcpKeepalive ) -> io:: Result < ( ) > {
1184
1193
#[ cfg( not( any(
1185
1194
target_os = "haiku" ,
1186
1195
target_os = "openbsd" ,
@@ -1241,13 +1250,13 @@ fn into_secs(duration: Duration) -> c_int {
1241
1250
1242
1251
/// Get the flags using `cmd`.
1243
1252
#[ cfg( not( target_os = "vita" ) ) ]
1244
- fn fcntl_get ( fd : Socket , cmd : c_int ) -> io:: Result < c_int > {
1253
+ fn fcntl_get ( fd : RawSocket , cmd : c_int ) -> io:: Result < c_int > {
1245
1254
syscall ! ( fcntl( fd, cmd) )
1246
1255
}
1247
1256
1248
1257
/// Add `flag` to the current set flags of `F_GETFD`.
1249
1258
#[ cfg( not( target_os = "vita" ) ) ]
1250
- fn fcntl_add ( fd : Socket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
1259
+ fn fcntl_add ( fd : RawSocket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
1251
1260
let previous = fcntl_get ( fd, get_cmd) ?;
1252
1261
let new = previous | flag;
1253
1262
if new != previous {
@@ -1260,7 +1269,7 @@ fn fcntl_add(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Res
1260
1269
1261
1270
/// Remove `flag` to the current set flags of `F_GETFD`.
1262
1271
#[ cfg( not( target_os = "vita" ) ) ]
1263
- fn fcntl_remove ( fd : Socket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
1272
+ fn fcntl_remove ( fd : RawSocket , get_cmd : c_int , set_cmd : c_int , flag : c_int ) -> io:: Result < ( ) > {
1264
1273
let previous = fcntl_get ( fd, get_cmd) ?;
1265
1274
let new = previous & !flag;
1266
1275
if new != previous {
@@ -1272,7 +1281,7 @@ fn fcntl_remove(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::
1272
1281
}
1273
1282
1274
1283
/// Caller must ensure `T` is the correct type for `opt` and `val`.
1275
- pub ( crate ) unsafe fn getsockopt < T > ( fd : Socket , opt : c_int , val : c_int ) -> io:: Result < T > {
1284
+ pub ( crate ) unsafe fn getsockopt < T > ( fd : RawSocket , opt : c_int , val : c_int ) -> io:: Result < T > {
1276
1285
let mut payload: MaybeUninit < T > = MaybeUninit :: uninit ( ) ;
1277
1286
let mut len = size_of :: < T > ( ) as libc:: socklen_t ;
1278
1287
syscall ! ( getsockopt(
@@ -1291,7 +1300,7 @@ pub(crate) unsafe fn getsockopt<T>(fd: Socket, opt: c_int, val: c_int) -> io::Re
1291
1300
1292
1301
/// Caller must ensure `T` is the correct type for `opt` and `val`.
1293
1302
pub ( crate ) unsafe fn setsockopt < T > (
1294
- fd : Socket ,
1303
+ fd : RawSocket ,
1295
1304
opt : c_int ,
1296
1305
val : c_int ,
1297
1306
payload : T ,
@@ -1365,7 +1374,7 @@ pub(crate) const fn to_mreqn(
1365
1374
feature = "all" ,
1366
1375
any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" )
1367
1376
) ) ]
1368
- pub ( crate ) fn original_dst_v4 ( fd : Socket ) -> io:: Result < SockAddr > {
1377
+ pub ( crate ) fn original_dst_v4 ( fd : RawSocket ) -> io:: Result < SockAddr > {
1369
1378
// Safety: `getsockopt` initialises the `SockAddr` for us.
1370
1379
unsafe {
1371
1380
SockAddr :: try_init ( |storage, len| {
@@ -1386,7 +1395,7 @@ pub(crate) fn original_dst_v4(fd: Socket) -> io::Result<SockAddr> {
1386
1395
/// This value contains the original destination IPv6 address of the connection
1387
1396
/// redirected using `ip6tables` `REDIRECT` or `TPROXY`.
1388
1397
#[ cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) ]
1389
- pub ( crate ) fn original_dst_v6 ( fd : Socket ) -> io:: Result < SockAddr > {
1398
+ pub ( crate ) fn original_dst_v6 ( fd : RawSocket ) -> io:: Result < SockAddr > {
1390
1399
// Safety: `getsockopt` initialises the `SockAddr` for us.
1391
1400
unsafe {
1392
1401
SockAddr :: try_init ( |storage, len| {
0 commit comments