mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
[Windows] Use recv instead of read (#3357)
This commit is contained in:
1 parent
0878179234
commit
aff71b37f5
3 files changed
+20
-3
No files matched your search
@@ -720,7 +720,7 @@ extension NIOBSDSocket {
|
||||
extension IOVector {
|
||||
// An initializer thats maps `ByteBuffer`` derived pointers to WSABUF. This allows us to use the
|
||||
// same initializer, that we use for iovecs on Windows.
|
||||
init(iov_base: UnsafeMutableRawPointer, iov_len: UInt32) {
|
||||
init(iov_base: UnsafeMutableRawPointer!, iov_len: UInt32) {
|
||||
self = WSABUF(
|
||||
len: iov_len,
|
||||
buf: iov_base.assumingMemoryBound(to: Int8.self)
|
||||
|
||||
@@ -224,8 +224,12 @@ class Socket: BaseSocket, SocketProtocol {
|
||||
/// - Returns: The `IOResult` which indicates how much data could be read and if the operation returned before all could be read (because the socket is in non-blocking mode).
|
||||
/// - Throws: An `IOError` if the operation failed.
|
||||
func read(pointer: UnsafeMutableRawBufferPointer) throws -> IOResult<Int> {
|
||||
try withUnsafeHandle {
|
||||
try Posix.read(descriptor: $0, pointer: pointer.baseAddress!, size: pointer.count)
|
||||
try withUnsafeHandle { (handle) -> IOResult<Int> in
|
||||
#if os(Windows)
|
||||
try Windows.recv(socket: handle, pointer: pointer.baseAddress!, size: Int32(pointer.count), flags: 0)
|
||||
#else
|
||||
try Posix.read(descriptor: handle, pointer: pointer.baseAddress!, size: pointer.count)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,19 @@ extension NIOCore.Windows {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
static func recv(
|
||||
socket: SOCKET,
|
||||
pointer: UnsafeMutableRawPointer,
|
||||
size: Int32,
|
||||
flags: Int32
|
||||
) throws -> IOResult<Int> {
|
||||
let result = WinSDK.recv(socket, pointer.assumingMemoryBound(to: CChar.self), size, flags)
|
||||
if result == WinSDK.SOCKET_ERROR {
|
||||
throw IOError(winsock: WSAGetLastError(), reason: "accept")
|
||||
}
|
||||
return .processed(Int(result))
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user