@@ -332,13 +332,11 @@ { OFString *destinationHost = host; uint16_t destinationPort = port; if (_socket != INVALID_SOCKET) - @throw [OFAlreadyConnectedException - exceptionWithClass: [self class] - socket: self]; + @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if (_SOCKS5Host != nil) { /* Connect to the SOCKS5 proxy instead */ host = _SOCKS5Host; port = _SOCKS5Port; @@ -355,13 +353,12 @@ snprintf(portCString, 7, "%" PRIu16, port); if (getaddrinfo([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE], portCString, &hints, &res0)) @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class] - socket: self - host: host]; + exceptionWithHost: host + socket: self]; for (res = res0; res != NULL; res = res->ai_next) { if ((_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == INVALID_SOCKET) continue; @@ -392,25 +389,23 @@ if ((addr.sin_addr.s_addr = inet_addr([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) != (in_addr_t)(-1)) { if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: host - port: port]; + exceptionWithHost: host + port: port + socket: self]; } if (connect(_socket, (struct sockaddr*)&addr, sizeof(addr)) == -1) { close(_socket); _socket = INVALID_SOCKET; @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: host - port: port]; + exceptionWithHost: host + port: port + socket: self]; } if (_SOCKS5Host != nil) [self OF_SOCKS5ConnectToHost: destinationHost port: destinationPort]; @@ -428,26 +423,23 @@ # ifdef OF_HAVE_THREADS [addrlist release]; [mutex unlock]; # endif @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class] - socket: self - host: host]; + exceptionWithHost: host + socket: self]; } if (he->h_addrtype != AF_INET || (_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { # ifdef OF_HAVE_THREADS [addrlist release]; [mutex unlock]; # endif - @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFConnectionFailedException exceptionWithHost: host + port: port + socket: self]; } # ifdef OF_HAVE_THREADS @try { for (ip = he->h_addr_list; *ip != NULL; ip++) @@ -485,15 +477,13 @@ _socket = INVALID_SOCKET; } #endif if (_socket == INVALID_SOCKET) - @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFConnectionFailedException exceptionWithHost: host + port: port + socket: self]; if (_SOCKS5Host != nil) [self OF_SOCKS5ConnectToHost: destinationHost port: destinationPort]; } @@ -550,18 +540,15 @@ #ifndef __wii__ socklen_t addrLen; #endif if (_socket != INVALID_SOCKET) - @throw [OFAlreadyConnectedException - exceptionWithClass: [self class] - socket: self]; + @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if (_SOCKS5Host != nil) - @throw [OFNotImplementedException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; #ifdef __wii__ if (port == 0) port = freePort--; #endif @@ -577,35 +564,30 @@ snprintf(portCString, 7, "%" PRIu16, port); if (getaddrinfo([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE], portCString, &hints, &res)) @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class] - socket: self - host: host]; + exceptionWithHost: host + socket: self]; if ((_socket = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) - @throw [OFBindFailedException exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithHost: host + port: port + socket: self]; if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one))) - @throw [OFSetOptionFailedException - exceptionWithClass: [self class] - stream: self]; + @throw [OFSetOptionFailedException exceptionWithStream: self]; if (bind(_socket, res->ai_addr, res->ai_addrlen) == -1) { freeaddrinfo(res); close(_socket); _socket = INVALID_SOCKET; - @throw [OFBindFailedException exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithHost: host + port: port + socket: self]; } freeaddrinfo(res); #else memset(&addr, 0, sizeof(addr)); @@ -621,20 +603,18 @@ struct hostent *he; if ((he = gethostbyname([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class] - socket: self - host: host]; + exceptionWithHost: host + socket: self]; if (he->h_addrtype != AF_INET || he->h_addr_list[0] == NULL) { @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class] - socket: self - host: host]; + exceptionWithHost: host + socket: self]; } memcpy(&addr.in.sin_addr.s_addr, he->h_addr_list[0], he->h_length); # ifdef OF_HAVE_THREADS @@ -643,28 +623,24 @@ } # endif } if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) - @throw [OFBindFailedException exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithHost: host + port: port + socket: self]; if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one))) - @throw [OFSetOptionFailedException - exceptionWithClass: [self class] - stream: self]; + @throw [OFSetOptionFailedException exceptionWithStream: self]; if (bind(_socket, (struct sockaddr*)&addr.in, sizeof(addr.in)) == -1) { close(_socket); _socket = INVALID_SOCKET; - @throw [OFBindFailedException exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithHost: host + port: port + socket: self]; } #endif if (port > 0) return port; @@ -672,14 +648,13 @@ #ifndef __wii__ addrLen = sizeof(addr.storage); if (getsockname(_socket, (struct sockaddr*)&addr, &addrLen)) { close(_socket); _socket = INVALID_SOCKET; - @throw [OFBindFailedException exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithHost: host + port: port + socket: self]; } if (addr.storage.ss_family == AF_INET) return OF_BSWAP16_IF_LE(addr.in.sin_port); # ifdef AF_INET6 @@ -688,26 +663,23 @@ # endif #endif close(_socket); _socket = INVALID_SOCKET; - @throw [OFBindFailedException exceptionWithClass: [self class] - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithHost: host + port: port + socket: self]; } - (void)listenWithBackLog: (int)backLog { if (_socket == INVALID_SOCKET) - @throw [OFNotConnectedException exceptionWithClass: [self class] - socket: self]; + @throw [OFNotConnectedException exceptionWithSocket: self]; if (listen(_socket, backLog) == -1) - @throw [OFListenFailedException exceptionWithClass: [self class] - socket: self - backLog: backLog]; + @throw [OFListenFailedException exceptionWithSocket: self + backLog: backLog]; _listening = true; } - (void)listen @@ -726,12 +698,11 @@ addrLen = sizeof(*addr); addr = [client allocMemoryWithSize: addrLen]; if ((socket = accept(_socket, (struct sockaddr*)addr, &addrLen)) == INVALID_SOCKET) - @throw [OFAcceptFailedException exceptionWithClass: [self class] - socket: self]; + @throw [OFAcceptFailedException exceptionWithSocket: self]; client->_socket = socket; client->_sockAddr = addr; client->_sockAddrLen = addrLen; @@ -757,32 +728,28 @@ - (void)setKeepAlivesEnabled: (bool)enable { int v = enable; if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) - @throw [OFSetOptionFailedException - exceptionWithClass: [self class] - stream: self]; + @throw [OFSetOptionFailedException exceptionWithStream: self]; } - (OFString*)remoteAddress { char *host; if (_sockAddr == NULL || _sockAddrLen == 0) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFNotConnectedException exceptionWithSocket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO host = [self allocMemoryWithSize: NI_MAXHOST]; @try { if (getnameinfo((struct sockaddr*)_sockAddr, _sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV)) @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class]]; + exceptionWithSocket: self]; return [OFString stringWithCString: host encoding: OF_STRING_ENCODING_NATIVE]; } @finally { [self freeMemory: host]; @@ -795,11 +762,11 @@ # endif host = inet_ntoa(((struct sockaddr_in*)_sockAddr)->sin_addr); if (host == NULL) @throw [OFAddressTranslationFailedException - exceptionWithClass: [self class]]; + exceptionWithSocket: self]; return [OFString stringWithCString: host encoding: OF_STRING_ENCODING_NATIVE]; # ifdef OF_HAVE_THREADS } @finally {