ObjFW  Check-in [657fae20a4]

Overview
Comment:Add - close to OFStream.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 657fae20a45455353cb0a88998158bcb40a8edf1748e34f2a165327ba6102aef
User & Date: js on 2008-12-07 10:35:12
Other Links: manifest | tags
Context
2008-12-07
10:39
Remove redundant method definitions. check-in: 06c6cdbd34 user: js tags: trunk
10:35
Add - close to OFStream. check-in: 657fae20a4 user: js tags: trunk
10:24
OFSocket -> OFTCPSocket. check-in: d1a5065e69 user: js tags: trunk
Changes

Modified src/OFFile.h from [4108e927d0] to [2c1ca1f133].

168
169
170
171
172
173
174





175
/**
 * Writes a C string into the file, without the trailing zero.
 *
 * \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;





@end







>
>
>
>
>

168
169
170
171
172
173
174
175
176
177
178
179
180
/**
 * Writes a C string into the file, without the trailing zero.
 *
 * \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

Modified src/OFFile.m from [44934e3ad8] to [249d4d336a].

160
161
162
163
164
165
166










167

- (size_t)writeCString: (const char*)str
{
	return [self writeNItems: strlen(str)
			  ofSize: 1
		      fromBuffer: (const uint8_t*)str];
}










@end







>
>
>
>
>
>
>
>
>
>

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

- (size_t)writeCString: (const char*)str
{
	return [self writeNItems: strlen(str)
			  ofSize: 1
		      fromBuffer: (const uint8_t*)str];
}

- close
{
	if (fclose(fp)) {
		/* FIXME: Throw exception */
		return nil;
	}

	return self;
}
@end

Modified src/OFStream.h from [1921fa4c55] to [794f822abd].

46
47
48
49
50
51
52





53
/**
 * Writes a C string into the stream, without the trailing zero.
 *
 * \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;





@end







>
>
>
>
>

46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * Writes a C string into the stream, without the trailing zero.
 *
 * \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

Modified src/OFTCPSocket.h from [89f3d3aa72] to [8a8e95826f].

70
71
72
73
74
75
76





77
/**
 * Sends a C string, without the trailing zero.
 *
 * \param str The C string from which the data is sent
 * \return The number of bytes written
 */
- (size_t)writeCString: (const char*)str;





@end







>
>
>
>
>

70
71
72
73
74
75
76
77
78
79
80
81
82
/**
 * Sends a C string, without the trailing zero.
 *
 * \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

Modified src/OFTCPSocket.m from [1175a4c331] to [ed0fb6187c].

115
116
117
118
119
120
121










122
}

- (size_t)writeCString: (const char*)str
{
	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}










@end







>
>
>
>
>
>
>
>
>
>

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
}

- (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

Modified tests/OFTCPSocket/OFTCPSocket.m from [6368be628d] to [134a575aa5].

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#import "OFTCPSocket.h"
#import "OFExceptions.h"

int
main()
{
	OFTCPSocket *sock;

	@try {
		sock = [OFTCPSocket new];
		[sock 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) {
		printf("EXCEPTION: %s\n", [e cString]);
	}

	return 0;
}







<
<

|
<
|










15
16
17
18
19
20
21


22
23

24
25
26
27
28
29
30
31
32
33
34

#import "OFTCPSocket.h"
#import "OFExceptions.h"

int
main()
{


	@try {
		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) {
		printf("EXCEPTION: %s\n", [e cString]);
	}

	return 0;
}