diff options
author | dom96 <dominikpicheta@googlemail.com> | 2010-10-27 19:06:25 +0100 |
---|---|---|
committer | dom96 <dominikpicheta@googlemail.com> | 2010-10-27 19:06:25 +0100 |
commit | 8733886e5370e507e4179932b5658be2ee696e0f (patch) | |
tree | 9e8f055f0065fb277768ca66a2ce97cb751c4c27 /lib | |
parent | 0879f0b0a7741dc725f1993b4490e00a13a640e0 (diff) | |
download | Nim-8733886e5370e507e4179932b5658be2ee696e0f.tar.gz |
Added a close function to the ssl module.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/impure/ssl.nim | 6 | ||||
-rw-r--r-- | lib/pure/smtp.nim | 5 | ||||
-rw-r--r-- | lib/wrappers/openssl.nim | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/lib/impure/ssl.nim b/lib/impure/ssl.nim index e90488a2b..ab53d0538 100644 --- a/lib/impure/ssl.nim +++ b/lib/impure/ssl.nim @@ -74,6 +74,12 @@ proc send*(sock: TSecureSocket, data: string) = if BIO_write(sock.bio, data, data.len()) <= 0: OSError() +proc close*(sock: TSecureSocket) = + ## Closes the socket + if BIO_free(sock.bio) <= 0: + ERR_print_errors_fp(stderr) + OSError() + when isMainModule: var s: TSecureSocket echo connect(s, "smtp.gmail.com", 465) diff --git a/lib/pure/smtp.nim b/lib/pure/smtp.nim index 88c05aaed..3490822b9 100644 --- a/lib/pure/smtp.nim +++ b/lib/pure/smtp.nim @@ -125,6 +125,7 @@ proc sendmail*(smtp: TSMTP, fromaddr: string, ## Sends `msg` from `fromaddr` to `toaddr`. ## Messages may be formed using ``createMessage`` by converting the ## TMessage into a string. + ## This function sends the QUIT command when finished. smtp.debugSend("MAIL FROM:<" & fromaddr & ">\c\L") smtp.checkReply("250") @@ -141,6 +142,10 @@ proc sendmail*(smtp: TSMTP, fromaddr: string, # quit 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], otherHeaders: openarray[tuple[name, value: string]]): TMessage = diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index b298a9fc4..5fc6ddd02 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -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, dynlib: DLLUtilName, importc.} +proc BIO_free*(b: PBIO): cInt{.cdecl, dynlib: DLLUtilName, importc.} + proc ERR_print_errors_fp*(fp: TFile){.cdecl, dynlib: DLLSSLName, importc.} when True: |