sockets.send now throws an exception when a non-blocking socket is
passed to it.
This commit is contained in:
parent
30bb68d48a
commit
8ac7bda244
1 changed files with 14 additions and 2 deletions
|
|
@ -1511,13 +1511,19 @@ proc send*(socket: TSocket, data: pointer, size: int): int {.
|
||||||
|
|
||||||
proc send*(socket: TSocket, data: string) {.tags: [FWriteIO].} =
|
proc send*(socket: TSocket, data: string) {.tags: [FWriteIO].} =
|
||||||
## sends data to a socket.
|
## sends data to a socket.
|
||||||
if send(socket, cstring(data), data.len) != data.len:
|
if socket.nonblocking:
|
||||||
|
raise newException(EInvalidValue, "This function cannot be used on non-blocking sockets.")
|
||||||
|
let sent = send(socket, cstring(data), data.len)
|
||||||
|
if sent < 0:
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
if socket.isSSL:
|
if socket.isSSL:
|
||||||
SSLError()
|
SSLError()
|
||||||
|
|
||||||
OSError(OSLastError())
|
OSError(OSLastError())
|
||||||
|
|
||||||
|
if sent != data.len:
|
||||||
|
raise newException(EOS, "Could not send all data.")
|
||||||
|
|
||||||
proc sendAsync*(socket: TSocket, data: string): int {.tags: [FWriteIO].} =
|
proc sendAsync*(socket: TSocket, data: string): int {.tags: [FWriteIO].} =
|
||||||
## sends data to a non-blocking socket.
|
## sends data to a non-blocking socket.
|
||||||
## Returns ``0`` if no data could be sent, if data has been sent
|
## Returns ``0`` if no data could be sent, if data has been sent
|
||||||
|
|
@ -1620,7 +1626,13 @@ proc setBlocking(s: TSocket, blocking: bool) =
|
||||||
if fcntl(s.fd, F_SETFL, mode) == -1:
|
if fcntl(s.fd, F_SETFL, mode) == -1:
|
||||||
OSError(OSLastError())
|
OSError(OSLastError())
|
||||||
s.nonblocking = not blocking
|
s.nonblocking = not blocking
|
||||||
|
|
||||||
|
discard """ proc setReuseAddr*(s: TSocket) =
|
||||||
|
var blah: int = 1
|
||||||
|
var mode = SO_REUSEADDR
|
||||||
|
if setsockopt(s.fd, SOL_SOCKET, mode, addr blah, TSOcklen(sizeof(int))) == -1:
|
||||||
|
OSError(OSLastError()) """
|
||||||
|
|
||||||
proc connect*(socket: TSocket, address: string, port = TPort(0), timeout: int,
|
proc connect*(socket: TSocket, address: string, port = TPort(0), timeout: int,
|
||||||
af: TDomain = AF_INET) {.tags: [FReadIO, FWriteIO].} =
|
af: TDomain = AF_INET) {.tags: [FReadIO, FWriteIO].} =
|
||||||
## Connects to server as specified by ``address`` on port specified by ``port``.
|
## Connects to server as specified by ``address`` on port specified by ``port``.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue