Fixed recvLine deprecation warnings.

This commit is contained in:
Dominik Picheta
2013-04-14 01:00:38 +01:00
parent 43499b9f07
commit e3d097c4e9
6 changed files with 72 additions and 80 deletions

View File

@@ -126,7 +126,7 @@ type
handleTask*: proc (s: PAsyncSocket) {.closure.}
lineBuffer: TaintedString ## Temporary storage for ``recvLine``
lineBuffer: TaintedString ## Temporary storage for ``readLine``
sendBuffer: string ## Temporary storage for ``send``
sslNeedAccept: bool
proto: TProtocol
@@ -635,7 +635,7 @@ when isMainModule:
proc testRead(s: PAsyncSocket, no: int) =
echo("Reading! " & $no)
var data = ""
if not s.recvLine(data):
if not s.readLine(data):
OSError()
if data == "":
echo("Closing connection. " & $no)

View File

@@ -124,7 +124,7 @@ template blockingOperation(sock: TSocket, body: stmt) {.immediate.} =
proc expectReply(ftp: PFTPClient): TaintedString =
result = TaintedString""
blockingOperation(ftp.getCSock()):
if not ftp.getCSock().recvLine(result): setLen(result.string, 0)
ftp.getCSock().readLine(result)
proc send*(ftp: PFTPClient, m: string): TaintedString =
## Send a message to the server, and wait for a primary reply.
@@ -280,19 +280,18 @@ proc getLines(ftp: PFTPClient, async: bool = false): bool =
if ftp.dsockConnected:
var r = TaintedString""
if ftp.isAsync:
if ftp.asyncDSock.recvLine(r):
if ftp.asyncDSock.readLine(r):
if r.string == "":
ftp.dsockConnected = false
else:
ftp.job.lines.add(r.string & "\n")
else:
assert(not async)
if ftp.dsock.recvLine(r):
if r.string == "":
ftp.dsockConnected = false
else:
ftp.job.lines.add(r.string & "\n")
else: OSError()
ftp.dsock.readLine(r)
if r.string == "":
ftp.dsockConnected = false
else:
ftp.job.lines.add(r.string & "\n")
if not async:
var readSocks: seq[TSocket] = @[ftp.getCSock()]

View File

@@ -100,27 +100,27 @@ proc parseChunks(s: TSocket, timeout: int): string =
while true:
var chunkSizeStr = ""
var chunkSize = 0
if s.recvLine(chunkSizeStr, timeout):
var i = 0
if chunkSizeStr == "":
httpError("Server terminated connection prematurely")
while true:
case chunkSizeStr[i]
of '0'..'9':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('0'))
of 'a'..'f':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('a') + 10)
of 'A'..'F':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('A') + 10)
of '\0':
break
of ';':
# http://tools.ietf.org/html/rfc2616#section-3.6.1
# We don't care about chunk-extensions.
break
else:
httpError("Invalid chunk size: " & chunkSizeStr)
inc(i)
s.readLine(chunkSizeStr, timeout)
var i = 0
if chunkSizeStr == "":
httpError("Server terminated connection prematurely")
while true:
case chunkSizeStr[i]
of '0'..'9':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('0'))
of 'a'..'f':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('a') + 10)
of 'A'..'F':
chunkSize = chunkSize shl 4 or (ord(chunkSizeStr[i]) - ord('A') + 10)
of '\0':
break
of ';':
# http://tools.ietf.org/html/rfc2616#section-3.6.1
# We don't care about chunk-extensions.
break
else:
httpError("Invalid chunk size: " & chunkSizeStr)
inc(i)
if chunkSize <= 0: break
result.setLen(ri+chunkSize)
var bytesRead = 0
@@ -175,39 +175,38 @@ proc parseResponse(s: TSocket, getBody: bool, timeout: int): TResponse =
while True:
line = ""
linei = 0
if s.recvLine(line, timeout):
if line == "": break # We've been disconnected.
if line == "\c\L":
fullyRead = true
break
if not parsedStatus:
# Parse HTTP version info and status code.
var le = skipIgnoreCase(line, "HTTP/", linei)
if le <= 0: httpError("invalid http version")
inc(linei, le)
le = skipIgnoreCase(line, "1.1", linei)
if le > 0: result.version = "1.1"
else:
le = skipIgnoreCase(line, "1.0", linei)
if le <= 0: httpError("unsupported http version")
result.version = "1.0"
inc(linei, le)
# Status code
linei.inc skipWhitespace(line, linei)
result.status = line[linei .. -1]
parsedStatus = true
s.readLine(line, timeout)
if line == "": break # We've been disconnected.
if line == "\c\L":
fullyRead = true
break
if not parsedStatus:
# Parse HTTP version info and status code.
var le = skipIgnoreCase(line, "HTTP/", linei)
if le <= 0: httpError("invalid http version")
inc(linei, le)
le = skipIgnoreCase(line, "1.1", linei)
if le > 0: result.version = "1.1"
else:
# Parse headers
var name = ""
var le = parseUntil(line, name, ':', linei)
if le <= 0: httpError("invalid headers")
inc(linei, le)
if line[linei] != ':': httpError("invalid headers")
inc(linei) # Skip :
linei += skipWhitespace(line, linei)
result.headers[name] = line[linei.. -1]
else: SocketError(s)
le = skipIgnoreCase(line, "1.0", linei)
if le <= 0: httpError("unsupported http version")
result.version = "1.0"
inc(linei, le)
# Status code
linei.inc skipWhitespace(line, linei)
result.status = line[linei .. -1]
parsedStatus = true
else:
# Parse headers
var name = ""
var le = parseUntil(line, name, ':', linei)
if le <= 0: httpError("invalid headers")
inc(linei, le)
if line[linei] != ':': httpError("invalid headers")
inc(linei) # Skip :
linei += skipWhitespace(line, linei)
result.headers[name] = line[linei.. -1]
if not fullyRead:
httpError("Connection was closed before full request has been made")
if getBody:

View File

@@ -345,10 +345,10 @@ proc poll*(irc: PIRC, ev: var TIRCEvent,
var socks = @[irc.sock]
var ret = socks.select(timeout)
if socks.len() == 0 and ret != 0:
if irc.sock.recvLine(line):
ev = irc.processLine(line.string)
result = true
irc.sock.readLine(line)
ev = irc.processLine(line.string)
result = true
if processOther(irc, ev): result = true
proc getLag*(irc: PIRC): float =
@@ -380,7 +380,7 @@ proc handleConnect(s: PAsyncSocket, irc: PAsyncIRC) =
proc handleRead(s: PAsyncSocket, irc: PAsyncIRC) =
var line = "".TaintedString
var ret = s.recvLine(line)
var ret = s.readLine(line)
if ret:
if line == "":
var ev: TIRCEvent

View File

@@ -28,9 +28,6 @@
## For SSL support this module relies on OpenSSL. If you want to
## enable SSL, compile with ``-d:ssl``.
when not defined(ssl):
{.error: "The SMTP module should be compiled with SSL support. Compile with -d:ssl."}
import sockets, strutils, strtabs, base64, os
type
@@ -54,16 +51,11 @@ proc debugSend(smtp: TSMTP, cmd: string) =
proc debugRecv(smtp: var TSMTP): TaintedString =
var line = TaintedString""
var ret = False
ret = smtp.sock.recvLine(line)
smtp.sock.readLine(line)
if ret:
if smtp.debug:
echo("S:" & line.string)
return line
else:
OSError()
return TaintedString""
if smtp.debug:
echo("S:" & line.string)
return line
proc quitExcpt(smtp: TSMTP, msg: string) =
smtp.debugSend("QUIT")

View File

@@ -35,6 +35,8 @@ Changes affecting backwards compatibility
-----------------------------------------
- ``shared`` is a keyword now.
- Deprecated ``sockets.recvLine`` and ``asyncio.recvLine``, added
``readLine`` instead.
Compiler Additions