if (opt != 0) {
SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
ea->Code = opt;
- ea->Message = FormatErrorCode(opt);
+ ea->Message = FormatErrorCode(ea->Code);
OnError(ea);
Close();
int rc = connect(GetFD(), (sockaddr *)&sin, sizeof(sin));
#ifdef _WIN32
- if (rc < 0 && WSAGetLastError() != WSAEWOULDBLOCK)
+ if (rc < 0 && WSAGetLastError() != WSAEWOULDBLOCK) {
#else /* _WIN32 */
- if (rc < 0 && errno != EINPROGRESS)
+ if (rc < 0 && errno != EINPROGRESS) {
#endif /* _WIN32 */
+ SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
+#ifdef _WIN32
+ ea->Code = WSAGetLastError();
+#else /* _WIN32 */
+ ea->Code = errno;
+#endif /* _WIN32 */
+ ea->Message = FormatErrorCode(ea->Code);
+
+ OnError(ea);
+
Close();
+ }
m_PeerHost = hostname;
m_PeerPort = port;
return 0;
if (rc <= 0) {
+ if (rc < 0) {
+ SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
+#ifdef _WIN32
+ ea->Code = WSAGetLastError();
+#else /* _WIN32 */
+ ea->Code = errno;
+#endif /* _WIN32 */
+ ea->Message = FormatErrorCode(ea->Code);
+
+ OnError(ea);
+ }
+
Close();
return 0;
}
rc = send(GetFD(), (const char *)m_SendQueue->GetReadBuffer(), m_SendQueue->GetSize(), 0);
if (rc <= 0) {
+ if (rc < 0) {
+ SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
+#ifdef _WIN32
+ ea->Code = WSAGetLastError();
+#else /* _WIN32 */
+ ea->Code = errno;
+#endif /* _WIN32 */
+ ea->Message = FormatErrorCode(ea->Code);
+
+ OnError(ea);
+ }
+
Close();
return 0;
}
int fd = socket(AF_INET, SOCK_STREAM, 0);
- if (fd == INVALID_SOCKET)
- throw exception(/*"socket() failed."*/);
+ if (fd == INVALID_SOCKET) {
+ SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
+#ifdef _WIN32
+ ea->Code = WSAGetLastError();
+#else /* _WIN32 */
+ ea->Code = errno;
+#endif /* _WIN32 */
+ ea->Message = FormatErrorCode(ea->Code);
+ OnError(ea);
+ }
SetFD(fd);
}
int rc = ::bind(GetFD(), (sockaddr *)&sin, sizeof(sin));
- if (rc < 0)
+ if (rc < 0) {
+ SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
+#ifdef _WIN32
+ ea->Code = WSAGetLastError();
+#else /* _WIN32 */
+ ea->Code = errno;
+#endif /* _WIN32 */
+ ea->Message = FormatErrorCode(ea->Code);
+
+ OnError(ea);
+
Close();
+ }
}