Added a close function to the ssl module.

This commit is contained in:
dom96 2010-10-27 19:06:25 +01:00
commit 8733886e53
3 changed files with 13 additions and 0 deletions

View file

@ -74,6 +74,12 @@ proc send*(sock: TSecureSocket, data: string) =
if BIO_write(sock.bio, data, data.len()) <= 0: if BIO_write(sock.bio, data, data.len()) <= 0:
OSError() OSError()
proc close*(sock: TSecureSocket) =
## Closes the socket
if BIO_free(sock.bio) <= 0:
ERR_print_errors_fp(stderr)
OSError()
when isMainModule: when isMainModule:
var s: TSecureSocket var s: TSecureSocket
echo connect(s, "smtp.gmail.com", 465) echo connect(s, "smtp.gmail.com", 465)

View file

@ -125,6 +125,7 @@ proc sendmail*(smtp: TSMTP, fromaddr: string,
## Sends `msg` from `fromaddr` to `toaddr`. ## Sends `msg` from `fromaddr` to `toaddr`.
## Messages may be formed using ``createMessage`` by converting the ## Messages may be formed using ``createMessage`` by converting the
## TMessage into a string. ## TMessage into a string.
## This function sends the QUIT command when finished.
smtp.debugSend("MAIL FROM:<" & fromaddr & ">\c\L") smtp.debugSend("MAIL FROM:<" & fromaddr & ">\c\L")
smtp.checkReply("250") smtp.checkReply("250")
@ -141,6 +142,10 @@ proc sendmail*(smtp: TSMTP, fromaddr: string,
# quit # quit
smtp.debugSend("QUIT\c\L") smtp.debugSend("QUIT\c\L")
if not smtp.ssl:
smtp.sock.close()
else:
smtp.sslSock.close()
proc createMessage*(mSubject, mBody: string, mTo, mCc: seq[string], proc createMessage*(mSubject, mBody: string, mTo, mCc: seq[string],
otherHeaders: openarray[tuple[name, value: string]]): TMessage = otherHeaders: openarray[tuple[name, value: string]]): TMessage =

View file

@ -223,6 +223,8 @@ proc BIO_read*(b: PBIO, data: cstring, length: cInt): cInt{.cdecl,
proc BIO_write*(b: PBIO, data: cstring, length: cInt): cInt{.cdecl, proc BIO_write*(b: PBIO, data: cstring, length: cInt): cInt{.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc BIO_free*(b: PBIO): cInt{.cdecl, dynlib: DLLUtilName, importc.}
proc ERR_print_errors_fp*(fp: TFile){.cdecl, dynlib: DLLSSLName, importc.} proc ERR_print_errors_fp*(fp: TFile){.cdecl, dynlib: DLLSSLName, importc.}
when True: when True: