|
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 | + platform_is_not :windows, :linux do |
| 26 | + it "returns an array with data and information on the sender" do |
| 27 | + @client.send("foobar", 0) |
| 28 | + sock = @server.accept |
| 29 | + data = sock.recvfrom(6) |
| 30 | + data.should == ["foobar", ["AF_UNIX", ""]] |
| 31 | + sock.close |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + platform_is :linux do |
| 36 | + # It isn't clear which platforms support remote addresses here, so only Linux tests this. |
| 37 | + it "returns an array with data and information on the sender" do |
| 38 | + @client.send("foobar", 0) |
| 39 | + sock = @server.accept |
| 40 | + data = sock.recvfrom(6) |
| 41 | + data.should == ["foobar", ["AF_UNIX", ""]] |
| 42 | + sock.send("barfoo", 0) |
| 43 | + data = @client.recvfrom(6) |
| 44 | + data.should == ["barfoo", ["AF_UNIX", @server.local_address.unix_path]] |
| 45 | + sock.close |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + platform_is :windows do |
| 50 | + it "returns an Array containing the data and address information" do |
| 51 | + # The second part of the address is a memory dump on Windows! |
| 52 | + # See https://bugs.ruby-lang.org/issues/21702 |
| 53 | + @client.send("foobar", 0) |
| 54 | + sock = @server.accept |
| 55 | + data = sock.recvfrom(6) |
| 56 | + (data in ["foobar", ["AF_UNIX", String]]).should be_true |
| 57 | + sock.send("barfoo", 0) |
| 58 | + data = @client.recvfrom(6) |
| 59 | + (data in ["barfoo", ["AF_UNIX", String]]).should be_true |
| 60 | + sock.close |
| 61 | + end |
32 | 62 | end |
33 | 63 |
|
34 | 64 | it "allows an output buffer as third argument" do |
|
54 | 84 | buffer.encoding.should == Encoding::ISO_8859_1 |
55 | 85 | end |
56 | 86 |
|
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) |
| 87 | + platform_is_not :windows do |
| 88 | + it "uses different message options" do |
| 89 | + @client.send("foobar", Socket::MSG_PEEK) |
| 90 | + sock = @server.accept |
| 91 | + peek_data = sock.recvfrom(6, Socket::MSG_PEEK) # Does not retrieve the message |
| 92 | + real_data = sock.recvfrom(6) |
62 | 93 |
|
63 | | - real_data.should == peek_data |
64 | | - peek_data.should == ["foobar", ["AF_UNIX", ""]] |
65 | | - sock.close |
| 94 | + real_data.should == peek_data |
| 95 | + peek_data.should == ["foobar", ["AF_UNIX", ""]] |
| 96 | + sock.close |
| 97 | + end |
66 | 98 | end |
67 | 99 | end |
68 | 100 |
|
|
78 | 110 | @server.close |
79 | 111 | end |
80 | 112 |
|
81 | | - it 'returns an Array containing the data and address information' do |
82 | | - @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] |
| 113 | + platform_is_not :windows do |
| 114 | + it 'returns an Array containing the data and address information' do |
| 115 | + @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']] |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + platform_is :windows do |
| 120 | + it 'returns an Array containing the data and address information' do |
| 121 | + # The second part of the address is a memory dump on Windows! |
| 122 | + # See https://bugs.ruby-lang.org/issues/21702 |
| 123 | + (@server.recvfrom(5) in ['hello', ['AF_UNIX', String]]).should be_true |
| 124 | + end |
83 | 125 | end |
84 | 126 | end |
85 | 127 |
|
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) |
| 128 | + platform_is_not :windows do |
| 129 | + # These specs are taken from the rdoc examples on UNIXSocket#recvfrom. |
| 130 | + describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do |
| 131 | + before do |
| 132 | + @path1 = SocketSpecs.socket_path |
| 133 | + @path2 = SocketSpecs.socket_path.chop + '2' |
| 134 | + rm_r(@path2) |
92 | 135 |
|
93 | | - @client_raw = Socket.new(:UNIX, :DGRAM) |
94 | | - @client_raw.bind(Socket.sockaddr_un(@path1)) |
| 136 | + @client_raw = Socket.new(:UNIX, :DGRAM) |
| 137 | + @client_raw.bind(Socket.sockaddr_un(@path1)) |
95 | 138 |
|
96 | | - @server_raw = Socket.new(:UNIX, :DGRAM) |
97 | | - @server_raw.bind(Socket.sockaddr_un(@path2)) |
| 139 | + @server_raw = Socket.new(:UNIX, :DGRAM) |
| 140 | + @server_raw.bind(Socket.sockaddr_un(@path2)) |
98 | 141 |
|
99 | | - @socket = UNIXSocket.for_fd(@server_raw.fileno) |
100 | | - @socket.autoclose = false |
101 | | - end |
| 142 | + @socket = UNIXSocket.for_fd(@server_raw.fileno) |
| 143 | + @socket.autoclose = false |
| 144 | + end |
102 | 145 |
|
103 | | - after do |
104 | | - @client_raw.close |
105 | | - @server_raw.close # also closes @socket |
| 146 | + after do |
| 147 | + @client_raw.close |
| 148 | + @server_raw.close # also closes @socket |
106 | 149 |
|
107 | | - rm_r @path1 |
108 | | - rm_r @path2 |
109 | | - end |
| 150 | + rm_r @path1 |
| 151 | + rm_r @path2 |
| 152 | + end |
110 | 153 |
|
111 | | - it 'returns an Array containing the data and address information' do |
112 | | - @client_raw.send('hello', 0, Socket.sockaddr_un(@path2)) |
| 154 | + it 'returns an Array containing the data and address information' do |
| 155 | + @client_raw.send('hello', 0, Socket.sockaddr_un(@path2)) |
113 | 156 |
|
114 | | - @socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]] |
| 157 | + @socket.recvfrom(5).should == ['hello', ['AF_UNIX', @path1]] |
| 158 | + end |
115 | 159 | end |
116 | 160 | end |
117 | 161 | end |
|
0 commit comments