Skip to content

Commit 1b77162

Browse files
committed
Use c_int instead of i32 where appropriate
On most OSs and architectures the int type is 32 bits, however the C spec only requires int to be 16 bits, this way we stay compatible.
1 parent 9c4a404 commit 1b77162

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/socket.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl Socket {
172172
///
173173
/// An error will be returned if `listen` or `connect` has already been
174174
/// called on this builder.
175-
pub fn listen(&self, backlog: i32) -> io::Result<()> {
175+
pub fn listen(&self, backlog: c_int) -> io::Result<()> {
176176
sys::listen(self.inner, backlog)
177177
}
178178

@@ -375,7 +375,7 @@ impl Socket {
375375
pub fn recv_vectored_with_flags(
376376
&self,
377377
bufs: &mut [MaybeUninitSlice<'_>],
378-
flags: i32,
378+
flags: c_int,
379379
) -> io::Result<(usize, RecvFlags)> {
380380
sys::recv_vectored(self.inner, bufs, flags)
381381
}
@@ -417,7 +417,7 @@ impl Socket {
417417
pub fn recv_from_with_flags(
418418
&self,
419419
buf: &mut [MaybeUninit<u8>],
420-
flags: i32,
420+
flags: c_int,
421421
) -> io::Result<(usize, SockAddr)> {
422422
sys::recv_from(self.inner, buf, flags)
423423
}
@@ -457,7 +457,7 @@ impl Socket {
457457
pub fn recv_from_vectored_with_flags(
458458
&self,
459459
bufs: &mut [MaybeUninitSlice<'_>],
460-
flags: i32,
460+
flags: c_int,
461461
) -> io::Result<(usize, RecvFlags, SockAddr)> {
462462
sys::recv_from_vectored(self.inner, bufs, flags)
463463
}
@@ -494,7 +494,7 @@ impl Socket {
494494
/// `send` call.
495495
///
496496
/// [`send`]: #method.send
497-
pub fn send_with_flags(&self, buf: &[u8], flags: i32) -> io::Result<usize> {
497+
pub fn send_with_flags(&self, buf: &[u8], flags: c_int) -> io::Result<usize> {
498498
sys::send(self.inner, buf, flags)
499499
}
500500

@@ -509,7 +509,11 @@ impl Socket {
509509
///
510510
/// [`send_vectored`]: Socket::send_vectored
511511
#[cfg(not(target_os = "redox"))]
512-
pub fn send_vectored_with_flags(&self, bufs: &[IoSlice<'_>], flags: i32) -> io::Result<usize> {
512+
pub fn send_vectored_with_flags(
513+
&self,
514+
bufs: &[IoSlice<'_>],
515+
flags: c_int,
516+
) -> io::Result<usize> {
513517
sys::send_vectored(self.inner, bufs, flags)
514518
}
515519

@@ -536,7 +540,12 @@ impl Socket {
536540
/// to the underlying `sendto` call.
537541
///
538542
/// [`send_to`]: Socket::send_to
539-
pub fn send_to_with_flags(&self, buf: &[u8], addr: &SockAddr, flags: i32) -> io::Result<usize> {
543+
pub fn send_to_with_flags(
544+
&self,
545+
buf: &[u8],
546+
addr: &SockAddr,
547+
flags: c_int,
548+
) -> io::Result<usize> {
540549
sys::send_to(self.inner, buf, addr, flags)
541550
}
542551

@@ -556,7 +565,7 @@ impl Socket {
556565
&self,
557566
bufs: &[IoSlice<'_>],
558567
addr: &SockAddr,
559-
flags: i32,
568+
flags: c_int,
560569
) -> io::Result<usize> {
561570
sys::send_to_vectored(self.inner, bufs, addr, flags)
562571
}

src/sys/unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ pub(crate) fn connect(fd: Socket, addr: &SockAddr) -> io::Result<()> {
404404
syscall!(connect(fd, addr.as_ptr(), addr.len())).map(|_| ())
405405
}
406406

407-
pub(crate) fn listen(fd: Socket, backlog: i32) -> io::Result<()> {
407+
pub(crate) fn listen(fd: Socket, backlog: c_int) -> io::Result<()> {
408408
syscall!(listen(fd, backlog)).map(|_| ())
409409
}
410410

src/sys/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub(crate) fn connect(socket: Socket, addr: &SockAddr) -> io::Result<()> {
220220
syscall!(connect(socket, addr.as_ptr(), addr.len()), PartialEq::ne, 0).map(|_| ())
221221
}
222222

223-
pub(crate) fn listen(socket: Socket, backlog: i32) -> io::Result<()> {
223+
pub(crate) fn listen(socket: Socket, backlog: c_int) -> io::Result<()> {
224224
syscall!(listen(socket, backlog), PartialEq::ne, 0).map(|_| ())
225225
}
226226

0 commit comments

Comments
 (0)