@@ -52,6 +52,58 @@ test('TCP client sndtimeo blocking test', function()
5252 error (" expected send timeout to occur" )
5353 end
5454
55+ client :close ()
56+ accepted :close ()
57+ server :close ()
58+ end )
59+
60+
61+
62+ test (' TCP client poll receive blocking test' , function ()
63+ local sock = assert (socket .create (" inet" , " stream" , " tcp" ))
64+ assert (sock :connect (" httpbin.org" , " http" ))
65+ assert (sock :send (" GET /delay/10 HTTP/1.1\r\n Host: httpbin.org\r\n\r\n " ))
66+ assert (sock :set_blocking (false ))
67+ sock :poll (250 , " in" )
68+ local res , err = sock :receive ()
69+ if res then
70+ error (" expected timeout error, got data" )
71+ end
72+ eq (err , " timeout" )
73+ end )
74+
75+ test (' TCP client poll send blocking test' , function ()
76+ -- Create a server that accepts but never reads
77+ local server = assert (socket .create (" inet" , " stream" , " tcp" ))
78+ assert (server :set_option (" reuseaddr" , 1 ))
79+ assert (server :bind (" 127.0.0.1" , " 0" )) -- bind to any available port
80+ assert (server :listen (1 ))
81+
82+ local _ , port = assert (server :get_name ())
83+
84+ -- Connect a client
85+ local client = assert (socket .create (" inet" , " stream" , " tcp" ))
86+ assert (client :connect (" 127.0.0.1" , tostring (port )))
87+
88+ -- Accept the connection but don't read from it
89+ local accepted = assert (server :accept ())
90+
91+ -- Set client to non-blocking mode so sends don't hang
92+ assert (client :set_blocking (false ))
93+
94+ -- Fill the send buffer completely
95+ local large_data = string.rep (" x" , 65536 )
96+ for i = 1 , 1000 do
97+ local bytes , err = client :send (large_data )
98+ if not bytes then
99+ break -- Buffer is full
100+ end
101+ end
102+
103+ -- Now poll should timeout because socket is not writable (buffer full)
104+ local result = client :poll (250 , " out" )
105+ eq (result , true )
106+
55107 client :close ()
56108 accepted :close ()
57109 server :close ()
0 commit comments