@@ -83,12 +83,12 @@ - (void)connectToHost: (OFString*)host port: (uint16_t)port { if (sock != INVALID_SOCKET) - @throw [OFAlreadyConnectedException newWithClass: isa - socket: self]; + @throw [OFAlreadyConnectedException exceptionWithClass: isa + socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res, *res0; char portCString[7]; @@ -97,13 +97,14 @@ hints.ai_socktype = SOCK_STREAM; snprintf(portCString, 7, "%" PRIu16, port); if (getaddrinfo([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE], portCString, &hints, &res0)) - @throw [OFAddressTranslationFailedException newWithClass: isa - socket: self - host: host]; + @throw [OFAddressTranslationFailedException + exceptionWithClass: isa + socket: self + host: host]; for (res = res0; res != NULL; res = res->ai_next) { if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == INVALID_SOCKET) continue; @@ -134,13 +135,14 @@ OF_STRING_ENCODING_NATIVE])) == NULL) { # ifdef OF_THREADS [addrlist release]; [mutex unlock]; # endif - @throw [OFAddressTranslationFailedException newWithClass: isa - socket: self - host: host]; + @throw [OFAddressTranslationFailedException + exceptionWithClass: isa + socket: self + host: host]; } memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = of_bswap16_if_le(port); @@ -149,14 +151,14 @@ (sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { # ifdef OF_THREADS [addrlist release]; [mutex unlock]; # endif - @throw [OFConnectionFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFConnectionFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; } # ifdef OF_THREADS @try { for (ip = he->h_addr_list; *ip != NULL; ip++) @@ -193,14 +195,14 @@ sock = INVALID_SOCKET; } #endif if (sock == INVALID_SOCKET) - @throw [OFConnectionFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFConnectionFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; } - (uint16_t)bindToHost: (OFString*)host port: (uint16_t)port { @@ -210,12 +212,12 @@ struct sockaddr_in6 in6; } addr; socklen_t addrLen; if (sock != INVALID_SOCKET) - @throw [OFAlreadyConnectedException newWithClass: isa - socket: self]; + @throw [OFAlreadyConnectedException exceptionWithClass: isa + socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res; char portCString[7]; @@ -224,28 +226,29 @@ hints.ai_socktype = SOCK_STREAM; snprintf(portCString, 7, "%" PRIu16, port); if (getaddrinfo([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE], portCString, &hints, &res)) - @throw [OFAddressTranslationFailedException newWithClass: isa - socket: self - host: host]; + @throw [OFAddressTranslationFailedException + exceptionWithClass: isa + socket: self + host: host]; if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) - @throw [OFBindFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) { freeaddrinfo(res); close(sock); sock = INVALID_SOCKET; - @throw [OFBindFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; } freeaddrinfo(res); #else struct hostent *he; @@ -257,13 +260,14 @@ if ((he = gethostbyname([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) { # ifdef OF_THREADS [mutex unlock]; # endif - @throw [OFAddressTranslationFailedException newWithClass: isa - socket: self - host: host]; + @throw [OFAddressTranslationFailedException + exceptionWithClass: isa + socket: self + host: host]; } memset(&addr, 0, sizeof(addr)); addr.in.sin_family = AF_INET; addr.in.sin_port = of_bswap16_if_le(port); @@ -270,33 +274,34 @@ if (he->h_addrtype != AF_INET || he->h_addr_list[0] == NULL) { # ifdef OF_THREADS [mutex unlock]; # endif - @throw [OFAddressTranslationFailedException newWithClass: isa - socket: self - host: host]; + @throw [OFAddressTranslationFailedException + exceptionWithClass: isa + socket: self + host: host]; } memcpy(&addr.in.sin_addr.s_addr, he->h_addr_list[0], he->h_length); # ifdef OF_THREADS [mutex unlock]; # endif if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) - @throw [OFBindFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; if (bind(sock, (struct sockaddr*)&addr.in, sizeof(addr.in)) == -1) { close(sock); sock = INVALID_SOCKET; - @throw [OFBindFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; } #endif if (port > 0) return port; @@ -303,53 +308,53 @@ addrLen = sizeof(addr.storage); if (getsockname(sock, (struct sockaddr*)&addr, &addrLen)) { close(sock); sock = INVALID_SOCKET; - @throw [OFBindFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; } if (addr.storage.ss_family == AF_INET) return of_bswap16_if_le(addr.in.sin_port); if (addr.storage.ss_family == AF_INET6) return of_bswap16_if_le(addr.in6.sin6_port); close(sock); sock = INVALID_SOCKET; - @throw [OFBindFailedException newWithClass: isa - socket: self - host: host - port: port]; + @throw [OFBindFailedException exceptionWithClass: isa + socket: self + host: host + port: port]; } - (void)listenWithBackLog: (int)backLog { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithClass: isa - socket: self]; + @throw [OFNotConnectedException exceptionWithClass: isa + socket: self]; if (listen(sock, backLog) == -1) - @throw [OFListenFailedException newWithClass: isa - socket: self - backLog: backLog]; + @throw [OFListenFailedException exceptionWithClass: isa + socket: self + backLog: backLog]; listening = YES; } - (void)listen { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithClass: isa - socket: self]; + @throw [OFNotConnectedException exceptionWithClass: isa + socket: self]; if (listen(sock, 5) == -1) - @throw [OFListenFailedException newWithClass: isa - socket: self - backLog: 5]; + @throw [OFListenFailedException exceptionWithClass: isa + socket: self + backLog: 5]; listening = YES; } - (OFTCPSocket*)accept @@ -370,12 +375,12 @@ } if ((newSock = accept(sock, (struct sockaddr*)addr, &addrLen)) == INVALID_SOCKET) { [newSocket release]; - @throw [OFAcceptFailedException newWithClass: isa - socket: self]; + @throw [OFAcceptFailedException exceptionWithClass: isa + socket: self]; } newSocket->sock = newSock; newSocket->sockAddr = addr; newSocket->sockAddrLen = addrLen; @@ -386,30 +391,30 @@ - (void)setKeepAlivesEnabled: (BOOL)enable { int v = enable; if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) - @throw [OFSetOptionFailedException newWithClass: isa - stream: self]; + @throw [OFSetOptionFailedException exceptionWithClass: isa + stream: self]; } - (OFString*)remoteAddress { char *host; if (sockAddr == NULL || sockAddrLen == 0) - @throw [OFInvalidArgumentException newWithClass: isa - selector: _cmd]; + @throw [OFInvalidArgumentException exceptionWithClass: isa + selector: _cmd]; #ifdef HAVE_THREADSAFE_GETADDRINFO host = [self allocMemoryWithSize: NI_MAXHOST]; @try { if (getnameinfo((struct sockaddr*)sockAddr, sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) @throw [OFAddressTranslationFailedException - newWithClass: isa]; + exceptionWithClass: isa]; return [OFString stringWithCString: host encoding: OF_STRING_ENCODING_NATIVE]; } @finally { [self freeMemory: host]; @@ -422,11 +427,11 @@ # endif host = inet_ntoa(((struct sockaddr_in*)sockAddr)->sin_addr); if (host == NULL) @throw [OFAddressTranslationFailedException - newWithClass: isa]; + exceptionWithClass: isa]; return [OFString stringWithCString: host encoding: OF_STRING_ENCODING_NATIVE]; # ifdef OF_THREADS } @finally {