ObjFW  Diff

Differences From Artifact [73c30083ac]:

To Artifact [befe14a593]:


19
20
21
22
23
24
25
26

27
28
29
30
31
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
62

63
64
65
66
67
68
69
19
20
21
22
23
24
25

26
27
28
29
30
31
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

62
63
64
65
66
67
68
69







-
+

















-
+






-
-
+
+




-
+




-
+







#import "OFArray.h"
#import "OFNumber.h"
#import "OFPair.h"
#import "OFStdIOStream.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFTCPSocket.h"
#import "OFURL.h"
#import "OFURI.h"

#define bufferLen 4096

@interface OFSock: OFObject <OFApplicationDelegate, OFStreamDelegate>
{
	char _buffer[bufferLen];
	OFMutableArray OF_GENERIC(OFPair OF_GENERIC(OFStream *, OFStream *) *)
	    *_streams;
	int _errors;
}
@end

OF_APPLICATION_DELEGATE(OFSock)

static OFPair OF_GENERIC(OFStream *, OFStream *) *
streamFromString(OFString *string)
{
	OFURL *URL;
	OFURI *URI;
	OFString *scheme;

	if ([string isEqual: @"-"])
		return [OFPair pairWithFirstObject: OFStdIn
				      secondObject: OFStdOut];

	URL = [OFURL URLWithString: string];
	scheme = URL.scheme;
	URI = [OFURI URIWithString: string];
	scheme = URI.scheme;

	if ([scheme isEqual: @"tcp"]) {
		OFTCPSocket *sock = [OFTCPSocket socket];

		if (URL.port == nil) {
		if (URI.port == nil) {
			[OFStdErr writeLine: @"Need a port!"];
			[OFApplication terminateWithStatus: 1];
		}

		[sock connectToHost: URL.host port: URL.port.shortValue];
		[sock connectToHost: URI.host port: URI.port.shortValue];
		return [OFPair pairWithFirstObject: sock secondObject: sock];
	}

	[OFStdErr writeFormat: @"Invalid protocol: %@\n", scheme];
	[OFApplication terminateWithStatus: 1];
	abort();
}