diff options
Diffstat (limited to '')
-rw-r--r-- | vmime/net/socket.hpp | 25 | ||||
-rw-r--r-- | vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp | 5 | ||||
-rwxr-xr-x | vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp | 10 | ||||
-rw-r--r-- | vmime/platforms/posix/posixSocket.hpp | 5 | ||||
-rw-r--r-- | vmime/platforms/windows/windowsSocket.hpp | 19 | ||||
-rw-r--r-- | vmime/security/sasl/SASLSocket.hpp | 3 |
6 files changed, 65 insertions, 2 deletions
diff --git a/vmime/net/socket.hpp b/vmime/net/socket.hpp index 0fac6514..4551e3e2 100644 --- a/vmime/net/socket.hpp +++ b/vmime/net/socket.hpp @@ -47,11 +47,17 @@ class socket : public object { public: + enum Status + { + STATUS_WOULDBLOCK = 0x1 /**< The receive operation would block. */ + }; + + virtual ~socket() { } /** Type used for lengths in streams. */ - typedef int size_type; + typedef long size_type; /** Connect to the specified address and port. @@ -84,7 +90,7 @@ public: * @param count maximum number of bytes to receive (size of buffer) * @return number of bytes received/written into output buffer */ - virtual int receiveRaw(char* buffer, const size_type count) = 0; + virtual size_type receiveRaw(char* buffer, const size_type count) = 0; /** Send (text) data to the socket. * @@ -99,6 +105,15 @@ public: */ virtual void sendRaw(const char* buffer, const size_type count) = 0; + /** Send (raw) data to the socket. + * Function may returns before all data is sent. + * + * @param buffer data to send + * @param count number of bytes to send (size of buffer) + * @return number of bytes sent + */ + virtual size_type sendRawNonBlocking(const char* buffer, const size_type count) = 0; + /** Return the preferred maximum block size when reading * from or writing to this stream. * @@ -106,6 +121,12 @@ public: */ virtual size_type getBlockSize() const = 0; + /** Return the current status of this socket. + * + * @return status flags for this socket + */ + virtual unsigned int getStatus() const = 0; + protected: socket() { } diff --git a/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp b/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp index 729923f3..ca113f17 100644 --- a/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp +++ b/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp @@ -70,9 +70,12 @@ public: void send(const string& buffer); void sendRaw(const char* buffer, const size_type count); + size_type sendRawNonBlocking(const char* buffer, const size_type count); size_type getBlockSize() const; + unsigned int getStatus() const; + private: void internalThrow(); @@ -97,6 +100,8 @@ private: ref <timeoutHandler> m_toHandler; exception* m_ex; + + unsigned int m_status; }; diff --git a/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp b/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp index 401fad12..ab4093f7 100755 --- a/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp +++ b/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp @@ -36,6 +36,8 @@ #include "vmime/net/tls/TLSSocket.hpp" +#include <memory> + #include <openssl/ssl.h> @@ -72,9 +74,12 @@ public: void send(const string& buffer); void sendRaw(const char* buffer, const size_type count); + size_type sendRawNonBlocking(const char* buffer, const size_type count); size_type getBlockSize() const; + unsigned int getStatus() const; + private: static int bio_write(BIO* bio, const char* buf, int len); @@ -87,8 +92,10 @@ private: void createSSLHandle(); + void internalThrow(); void handleError(int rc); + ref <TLSSession_OpenSSL> m_session; ref <socket> m_wrapped; @@ -100,6 +107,9 @@ private: ref <timeoutHandler> m_toHandler; SSL* m_ssl; + + // Last exception thrown from C BIO functions + std::auto_ptr <std::exception> m_ex; }; diff --git a/vmime/platforms/posix/posixSocket.hpp b/vmime/platforms/posix/posixSocket.hpp index 1332505b..78b1c0aa 100644 --- a/vmime/platforms/posix/posixSocket.hpp +++ b/vmime/platforms/posix/posixSocket.hpp @@ -55,9 +55,12 @@ public: void send(const vmime::string& buffer); void sendRaw(const char* buffer, const size_type count); + size_type sendRawNonBlocking(const char* buffer, const size_type count); size_type getBlockSize() const; + unsigned int getStatus() const; + protected: static void throwSocketError(const int err); @@ -68,6 +71,8 @@ private: char m_buffer[65536]; int m_desc; + + unsigned int m_status; }; diff --git a/vmime/platforms/windows/windowsSocket.hpp b/vmime/platforms/windows/windowsSocket.hpp index c41d8bfe..ca007a06 100644 --- a/vmime/platforms/windows/windowsSocket.hpp +++ b/vmime/platforms/windows/windowsSocket.hpp @@ -43,6 +43,7 @@ namespace windows { class windowsSocket : public vmime::net::socket { public: + windowsSocket(); windowsSocket(ref <vmime::net::timeoutHandler> th); ~windowsSocket(); @@ -58,15 +59,33 @@ public: void send(const vmime::string& buffer); void sendRaw(const char* buffer, const size_type count); + size_type sendRawNonBlocking(const char* buffer, const size_type count); size_type getBlockSize() const; + unsigned int getStatus() const; + +protected: + + void throwSocketError(const int err); + + enum WaitOpType + { + READ = 1, + WRITE = 2, + BOTH = 4 + }; + + void waitForData(const WaitOpType t, bool& timedOut); + private: ref <vmime::net::timeoutHandler> m_timeoutHandler; char m_buffer[65536]; SOCKET m_desc; + + unsigned int m_status; }; diff --git a/vmime/security/sasl/SASLSocket.hpp b/vmime/security/sasl/SASLSocket.hpp index f05ed424..d6f4ecd9 100644 --- a/vmime/security/sasl/SASLSocket.hpp +++ b/vmime/security/sasl/SASLSocket.hpp @@ -63,9 +63,12 @@ public: void send(const string& buffer); void sendRaw(const char* buffer, const size_type count); + size_type sendRawNonBlocking(const char* buffer, const size_type count); size_type getBlockSize() const; + unsigned int getStatus() const; + private: ref <SASLSession> m_session; |