@@ -85,18 +85,18 @@ @throw [OFAlreadyConnectedException newWithClass: isa socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res, *res0; - char port_s[7]; + char portCString[7]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - snprintf(port_s, 7, "%" PRIu16, port); + snprintf(portCString, 7, "%" PRIu16, port); - if (getaddrinfo([host cString], port_s, &hints, &res0)) + if (getaddrinfo([host cString], portCString, &hints, &res0)) @throw [OFAddressTranslationFailedException newWithClass: isa socket: self host: host]; for (res = res0; res != NULL; res = res->ai_next) { @@ -210,18 +210,18 @@ @throw [OFAlreadyConnectedException newWithClass: isa socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res; - char port_s[7]; + char portCString[7]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - snprintf(port_s, 7, "%" PRIu16, port); + snprintf(portCString, 7, "%" PRIu16, port); - if (getaddrinfo([host cString], port_s, &hints, &res)) + if (getaddrinfo([host cString], portCString, &hints, &res)) @throw [OFAddressTranslationFailedException newWithClass: isa socket: self host: host]; if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) @@ -345,36 +345,36 @@ isListening = YES; } - (OFTCPSocket*)accept { - OFTCPSocket *newsock; + OFTCPSocket *newSocket; struct sockaddr *addr; - socklen_t addrlen; - int s; + socklen_t addrLen; + int newSock; - newsock = [[[isa alloc] init] autorelease]; - addrlen = sizeof(struct sockaddr); + newSocket = [[[isa alloc] init] autorelease]; + addrLen = sizeof(struct sockaddr); @try { - addr = [newsock allocMemoryWithSize: sizeof(struct sockaddr)]; + addr = [newSocket allocMemoryWithSize: sizeof(struct sockaddr)]; } @catch (id e) { - [newsock release]; + [newSocket release]; @throw e; } - if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { - [newsock release]; + if ((newSock = accept(sock, addr, &addrLen)) == INVALID_SOCKET) { + [newSocket release]; @throw [OFAcceptFailedException newWithClass: isa socket: self]; } - newsock->sock = s; - newsock->sockAddr = addr; - newsock->sockAddrLen = addrlen; + newSocket->sock = newSock; + newSocket->sockAddr = addr; + newSocket->sockAddrLen = addrLen; - return newsock; + return newSocket; } - (void)setKeepAlivesEnabled: (BOOL)enable { int v = enable; @@ -384,16 +384,18 @@ stream: self]; } - (OFString*)remoteAddress { + char *host; + if (sockAddr == NULL || sockAddrLen == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; #ifdef HAVE_THREADSAFE_GETADDRINFO - char *host = [self allocMemoryWithSize: NI_MAXHOST]; + host = [self allocMemoryWithSize: NI_MAXHOST]; @try { if (getnameinfo(sockAddr, sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) @throw [OFAddressTranslationFailedException @@ -402,12 +404,10 @@ return [OFString stringWithCString: host]; } @finally { [self freeMemory: host]; } #else - char *host; - # ifdef OF_THREADS [mutex lock]; @try { # endif