@@ -80,11 +80,12 @@ - (void)connectToHost: (OFString*)host onPort: (uint16_t)port { if (sock != INVALID_SOCKET) - @throw [OFAlreadyConnectedException newWithClass: isa]; + @throw [OFAlreadyConnectedException newWithClass: isa + socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res, *res0; char port_s[7]; @@ -93,10 +94,11 @@ hints.ai_socktype = SOCK_STREAM; snprintf(port_s, 7, "%" PRIu16, port); if (getaddrinfo([host cString], port_s, &hints, &res0)) @throw [OFAddressTranslationFailedException newWithClass: 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) @@ -142,10 +144,11 @@ # ifdef OF_THREADS [addrlist release]; [mutex unlock]; # endif @throw [OFConnectionFailedException newWithClass: isa + socket: self host: host port: port]; } # ifdef OF_THREADS @@ -185,19 +188,21 @@ } #endif if (sock == INVALID_SOCKET) @throw [OFConnectionFailedException newWithClass: isa + socket: self host: host port: port]; } - (void)bindToPort: (uint16_t)port onHost: (OFString*)host { if (sock != INVALID_SOCKET) - @throw [OFAlreadyConnectedException newWithClass: isa]; + @throw [OFAlreadyConnectedException newWithClass: isa + socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res; char port_s[7]; @@ -206,22 +211,25 @@ hints.ai_socktype = SOCK_STREAM; snprintf(port_s, 7, "%" PRIu16, port); if (getaddrinfo([host cString], port_s, &hints, &res)) @throw [OFAddressTranslationFailedException newWithClass: 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]; 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]; } freeaddrinfo(res); @@ -274,26 +282,30 @@ } - (void)listenWithBackLog: (int)backlog { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithClass: isa]; + @throw [OFNotConnectedException newWithClass: isa + socket: self]; if (listen(sock, backlog) == -1) @throw [OFListenFailedException newWithClass: isa + socket: self backLog: backlog]; listening = YES; } - (void)listen { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithClass: isa]; + @throw [OFNotConnectedException newWithClass: isa + socket: self]; if (listen(sock, 5) == -1) @throw [OFListenFailedException newWithClass: isa + socket: self backLog: 5]; listening = YES; } @@ -314,11 +326,12 @@ @throw e; } if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { [newsock release]; - @throw [OFAcceptFailedException newWithClass: isa]; + @throw [OFAcceptFailedException newWithClass: isa + socket: self]; } newsock->sock = s; newsock->sockAddr = addr; newsock->sockAddrLen = addrlen; @@ -385,14 +398,6 @@ [self freeMemory: sockAddr]; sockAddr = NULL; sockAddrLen = 0; } - -- (void)dealloc -{ - if (sock != INVALID_SOCKET) - [self close]; - - [super dealloc]; -} @end