|
15 | 15 | SocketSpecs.rm_socket @path |
16 | 16 | end |
17 | 17 |
|
18 | | - it "receives len bytes from sock" do |
| 18 | + it "receives len bytes from sock, returning an array containing sent data as first element" do |
19 | 19 | @client.send("foobar", 0) |
20 | 20 | sock = @server.accept |
21 | 21 | sock.recvfrom(6).first.should == "foobar" |
22 | 22 | sock.close |
23 | 23 | end |
24 | 24 |
|
25 | | - it "returns an array with data and information on the sender" do |
26 | | - @client.send("foobar", 0) |
27 | | - sock = @server.accept |
28 | | - data = sock.recvfrom(6) |
29 | | - data.first.should == "foobar" |
30 | | - data.last.should == ["AF_UNIX", ""] |
31 | | - sock.close |
| 25 | + context "when called on a server's socket" do |
| 26 | + platform_is_not :windows do |
| 27 | + it "returns an array containing basic information on the client as second element" do |
| 28 | + @client.send("foobar", 0) |
| 29 | + sock = @server.accept |
| 30 | + data = sock.recvfrom(6) |
| 31 | + data.last.should == ["AF_UNIX", ""] |
| 32 | + sock.close |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do |
| 37 | + it "returns an array containing basic information on the client as second element" do |
| 38 | + @client.send("foobar", 0) |
| 39 | + sock = @server.accept |
| 40 | + data = sock.recvfrom(6) |
| 41 | + data.last.should == ["AF_UNIX", ""] |
| 42 | + sock.close |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context "when called on a client's socket" do |
| 48 | + platform_is_not :windows, :darwin do |
| 49 | + it "returns an array containing server's address as second element" do |
| 50 | + @client.send("", 0) |
| 51 | + sock = @server.accept |
| 52 | + sock.send("barfoo", 0) |
| 53 | + @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path] |
| 54 | + sock.close |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do |
| 59 | + it "returns an array containing server's address as second element" do |
| 60 | + @client.send("", 0) |
| 61 | + sock = @server.accept |
| 62 | + sock.send("barfoo", 0) |
| 63 | + # This may not be correct, depends on what underlying recvfrom actually returns. |
| 64 | + @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path] |
| 65 | + sock.close |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + platform_is :darwin do |
| 70 | + it "returns an array containing basic information on the server as second element" do |
| 71 | + @client.send("", 0) |
| 72 | + sock = @server.accept |
| 73 | + sock.send("barfoo", 0) |
| 74 | + @client.recvfrom(6).last.should == ["AF_UNIX", ""] |
| 75 | + sock.close |
| 76 | + end |
| 77 | + end |
32 | 78 | end |
33 | 79 |
|
34 | 80 | it "allows an output buffer as third argument" do |
|
54 | 100 | buffer.encoding.should == Encoding::ISO_8859_1 |
55 | 101 | end |
56 | 102 |
|
57 | | - it "uses different message options" do |
58 | | - @client.send("foobar", Socket::MSG_PEEK) |
59 | | - sock = @server.accept |
60 | | - peek_data = sock.recvfrom(6, Socket::MSG_PEEK) # Does not retrieve the message |
61 | | - real_data = sock.recvfrom(6) |
| 103 | + platform_is_not :windows do |
| 104 | + it "uses different message options" do |
| 105 | + @client.send("foobar", Socket::MSG_PEEK) |
| 106 | + sock = @server.accept |
| 107 | + peek_data = sock.recvfrom(6, Socket::MSG_PEEK) # Does not retrieve the message |
| 108 | + real_data = sock.recvfrom(6) |
62 | 109 |
|
63 | | - real_data.should == peek_data |
64 | | - peek_data.should == ["foobar", ["AF_UNIX", ""]] |
65 | | - sock.close |
| 110 | + real_data.should == peek_data |
| 111 | + peek_data.should == ["foobar", ["AF_UNIX", ""]] |
| 112 | + sock.close |
| 113 | + end |
66 | 114 | end |
67 | 115 | end |
68 | 116 |
|
|
78 | 126 | @server.close |
79 | 127 | end |
80 | 128 |
|
81 | | - it 'returns an Array containing the data and address information' do |
82 | | - @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] |
| 129 | + platform_is_not :windows do |
| 130 | + it 'returns an Array containing the data and address information' do |
| 131 | + @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] |
| 132 | + end |
| 133 | + end |
| 134 | + |
| 135 | + guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.0" } do |
| 136 | + it 'returns an Array containing the data and address information' do |
| 137 | + @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] |
| 138 | + end |
83 | 139 | end |
84 | 140 | end |
85 | 141 |
|
86 | | - # These specs are taken from the rdoc examples on UNIXSocket#recvfrom. |
87 | | - describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do |
88 | | - before do |
89 | | - @path1 = SocketSpecs.socket_path |
90 | | - @path2 = SocketSpecs.socket_path.chop + '2' |
91 | | - rm_r(@path2) |
| 142 | + platform_is_not :windows do |
| 143 | + # These specs are taken from the rdoc examples on UNIXSocket#recvfrom. |
| 144 | + describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do |
| 145 | + before do |
| 146 | + @path1 = SocketSpecs.socket_path |
| 147 | + @path2 = SocketSpecs.socket_path.chop + '2' |
| 148 | + rm_r(@path2) |
92 | 149 |
|
93 | | - @client_raw = Socket.new(:UNIX, :DGRAM) |
94 | | - @client_raw.bind(Socket.sockaddr_un(@path1)) |
| 150 | + @client_raw = Socket.new(:UNIX, :DGRAM) |
| 151 | + @client_raw.bind(Socket.sockaddr_un(@path1)) |
95 | 152 |
|
96 | | - @server_raw = Socket.new(:UNIX, :DGRAM) |
97 | | - @server_raw.bind(Socket.sockaddr_un(@path2)) |
| 153 | + @server_raw = Socket.new(:UNIX, :DGRAM) |
| 154 | + @server_raw.bind(Socket.sockaddr_un(@path2)) |
98 | 155 |
|
99 | | - @socket = UNIXSocket.for_fd(@server_raw.fileno) |
100 | | - @socket.autoclose = false |
101 | | - end |
| 156 | + @socket = UNIXSocket.for_fd(@server_raw.fileno) |
| 157 | + @socket.autoclose = false |
| 158 | + end |
102 | 159 |
|
103 | | - after do |
104 | | - @client_raw.close |
105 | | - @server_raw.close # also closes @socket |
| 160 | + after do |
| 161 | + @client_raw.close |
| 162 | + @server_raw.close # also closes @socket |
106 | 163 |
|
107 | | - rm_r @path1 |
108 | | - rm_r @path2 |
109 | | - end |
| 164 | + rm_r @path1 |
| 165 | + rm_r @path2 |
| 166 | + end |
110 | 167 |
|
111 | | - it 'returns an Array containing the data and address information' do |
112 | | - @client_raw.send('hello', 0, Socket.sockaddr_un(@path2)) |
| 168 | + it 'returns an Array containing the data and address information' do |
| 169 | + @client_raw.send('hello', 0, Socket.sockaddr_un(@path2)) |
113 | 170 |
|
114 | | - @socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]] |
| 171 | + @socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]] |
| 172 | + end |
115 | 173 | end |
116 | 174 | end |
117 | 175 | end |
|
0 commit comments