Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -170,6 +170,11 @@ * * \param str The C string from which the data is written to the file * \return The number of bytes written */ - (size_t)writeCString: (const char*)str; + +/** + * Closes the file. + */ +- close; @end Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -162,6 +162,16 @@ { return [self writeNItems: strlen(str) ofSize: 1 fromBuffer: (const uint8_t*)str]; } + +- close +{ + if (fclose(fp)) { + /* FIXME: Throw exception */ + return nil; + } + + return self; +} @end Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -48,6 +48,11 @@ * * \param str The C string from which the data is written to the stream * \return The number of bytes written */ - (size_t)writeCString: (const char*)str; + +/** + * Closes the stream. + */ +- close; @end Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -72,6 +72,11 @@ * * \param str The C string from which the data is sent * \return The number of bytes written */ - (size_t)writeCString: (const char*)str; + +/** + * Closes the OFTCPSocket. + */ +- close; @end Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -117,6 +117,16 @@ - (size_t)writeCString: (const char*)str { return [self writeNBytes: strlen(str) fromBuffer: (const uint8_t*)str]; } + +- close +{ + if (sock < 0) { + /* FIXME: Throw exception */ + return nil; + } + + return self; +} @end Index: tests/OFTCPSocket/OFTCPSocket.m ================================================================== --- tests/OFTCPSocket/OFTCPSocket.m +++ tests/OFTCPSocket/OFTCPSocket.m @@ -17,16 +17,13 @@ #import "OFExceptions.h" int main() { - OFTCPSocket *sock; - @try { - sock = [OFTCPSocket new]; - [sock connectTo: "webkeks.org" - onPort: 80]; + OFTCPSocket *sock = [[OFTCPSocket new] connectTo: "webkeks.org" + onPort: 80]; [sock writeCString: "GET / HTTP/1.1\r\n" "Host: webkeks.org\r\n\r\n"]; puts((char*)[sock readNBytes: 1024]); [sock free]; } @catch(OFException *e) {