ObjFW  Check-in [df7b88405a]

Overview
Comment:OFHTTPServer: Pass errors from listening socket.

This way, it is possible to recover from errors by e.g. stopping the
server in the main thread and then restarting it, or by just ignoring
the exception.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: df7b88405ad80d6b9eb0e791b6f2b87fe80675ed6ce3cfa57f8c45463ace4407
User & Date: js on 2012-12-27 11:21:43
Other Links: manifest | tags
Context
2012-12-28
02:46
Make 16 bit selector UIDs the default. check-in: 511a372fb8 user: js tags: trunk
2012-12-27
11:21
OFHTTPServer: Pass errors from listening socket. check-in: df7b88405a user: js tags: trunk
11:20
OFStreamObserver_kqueue: Return NO on error. check-in: e5157b2ba2 user: js tags: trunk
Changes

Modified src/OFHTTPServer.h from [e4f4f862dd] to [0320d9c75b].

32
33
34
35
36
37
38
















39
40
41
42
43
44
45
 *
 * @param server The HTTP server which received the request
 * @param request The request the HTTP server received
 * @return The reply the HTTP server should send to the client
 */
- (OFHTTPRequestReply*)server: (OFHTTPServer*)server
	    didReceiveRequest: (OFHTTPRequest*)request;
















@end

/*!
 * @brief A class for creating a simple HTTP server inside of applications.
 */
@interface OFHTTPServer: OFObject
{







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 *
 * @param server The HTTP server which received the request
 * @param request The request the HTTP server received
 * @return The reply the HTTP server should send to the client
 */
- (OFHTTPRequestReply*)server: (OFHTTPServer*)server
	    didReceiveRequest: (OFHTTPRequest*)request;

#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
/*!
 * @brief This method is called when the HTTP server's listening socket
 *	  encountered an exception.
 *
 * @param exception The exception that occurred on the HTTP server's listening
 *		    socket
 * @return Whether to continue listening. If you return NO, existing connections
 *	   will still be handled and you can start accepting new connections
 *	   again by calling @ref start again.
 */
-			  (BOOL)server: (OFHTTPServer*)server
  didReceiveExceptionOnListeningSocket: (OFException*)e;
@end

/*!
 * @brief A class for creating a simple HTTP server inside of applications.
 */
@interface OFHTTPServer: OFObject
{
132
133
134
135
136
137
138



 */
- (void)stop;

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










>
>
>
148
149
150
151
152
153
154
155
156
157
 */
- (void)stop;

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

@interface OFObject (OFHTTPServerDelegate) <OFHTTPServerDelegate>
@end

Modified src/OFHTTPServer.m from [80903ac435] to [f75ba40071].

640
641
642
643
644
645
646
647





648

649
650
651
652
653
654
655
656
657
658
659
660

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

	if (exception != nil)





		return NO;


	connection = [[[OFHTTPServer_Connection alloc]
	    initWithSocket: clientSocket
		    server: self] autorelease];

	[clientSocket asyncReadLineWithTarget: connection
				     selector: @selector(socket:didReadLine:
						  exception:)];

	return YES;
}
@end







|
>
>
>
>
>

>












640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666

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

	if (exception != nil) {
		if ([delegate respondsToSelector:
		    @selector(server:didReceiveExceptionOnListeningSocket:)])
			return [delegate		  server: self
			    didReceiveExceptionOnListeningSocket: exception];

		return NO;
	}

	connection = [[[OFHTTPServer_Connection alloc]
	    initWithSocket: clientSocket
		    server: self] autorelease];

	[clientSocket asyncReadLineWithTarget: connection
				     selector: @selector(socket:didReadLine:
						  exception:)];

	return YES;
}
@end