ObjFW  Check-in [a31bba0947]

Overview
Comment:OFHTTPServer: Make is possible to stop the server.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a31bba094760865f281a616594a23cf42ce2fc79e4892d3cdfcb1c900b629c30
User & Date: js on 2012-12-20 13:03:05
Other Links: manifest | tags
Context
2012-12-20
13:57
OFTimer: Make rescheduling possible. check-in: 4572170728 user: js tags: trunk
13:03
OFHTTPServer: Make is possible to stop the server. check-in: a31bba0947 user: js tags: trunk
01:10
Move block structs and functions to block.h. check-in: b5e1ba0f94 user: js tags: trunk
Changes

Modified src/OFHTTPServer.h from [d43ccf4c58] to [43b8941dbf].

124
125
126
127
128
129
130







131
132
133
134
135
136
137
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144







+
+
+
+
+
+
+







- (OFString*)name;

/*!
 * @brief Starts the HTTP server in the current thread's runloop.
 */
- (void)start;

/*!
 * @brief Stops the HTTP server, meaning it will not accept any new incoming
 *	  connections, but still handle existing connections until they are
 *	  finished or timed out.
 */
- (void)stop;

- (BOOL)OF_socket: (OFTCPSocket*)socket
  didAcceptSocket: (OFTCPSocket*)clientSocket
	exception: (OFException*)exception;
@end

@interface OFObject (OFHTTPServerDelegate) <OFHTTPServerDelegate>
@end

Modified src/OFHTTPServer.m from [bee3baba47] to [862d84b05e].

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
41
42
43
44
45
46
47

48
49
50
51
52
53
54







-








#define BUFFER_SIZE 1024

/*
 * FIXME: Currently, connections never time out, which means a DoS is possible.
 * TODO: Add support for chunked transfer encoding.
 * FIXME: Key normalization replaces headers like "DNT" with "Dnt".
 * FIXME: It is currently not possible to stop the server.
 * FIXME: Errors are not reported to the user.
 */

static const char*
status_code_to_string(short code)
{
	switch (code) {
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225







-
+








+







@implementation OFHTTPServer_Connection
- initWithSocket: (OFTCPSocket*)sock_
	  server: (OFHTTPServer*)server_
{
	self = [super init];

	sock = [sock_ retain];
	server = server_;
	server = [server_ retain];
	state = AWAITING_PROLOG;

	return self;
}

- (void)dealloc
{
	[sock release];
	[server release];
	[host release];
	[path release];
	[headers release];
	[POSTData release];

	[super dealloc];
}
592
593
594
595
596
597
598







599
600
601
602
603
604
605
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612







+
+
+
+
+
+
+







	[listeningSocket listen];

	[listeningSocket asyncAcceptWithTarget: self
				      selector: @selector(OF_socket:
						    didAcceptSocket:
						    exception:)];
}

- (void)stop
{
	[listeningSocket cancelAsyncRequests];
	[listeningSocket release];
	listeningSocket = nil;
}

- (BOOL)OF_socket: (OFTCPSocket*)socket
  didAcceptSocket: (OFTCPSocket*)clientSocket
	exception: (OFException*)exception
{
	OFHTTPServer_Connection *connection;