You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns any data received by the connected socket, at most `max` bytes.
7243
+
7244
+
This method is a synchronous operation just like the [send](#tcpsocksend) method and is 100% nonblocking.
7245
+
7246
+
In case of success, it returns the data received; in case of error, it returns `nil` with a string describing the error.
7247
+
7248
+
If the received data is more than this size, this method will return with exactly this size of data.
7249
+
The remaining data in the underlying receive buffer could be returned in the next reading operation.
7250
+
7251
+
Timeout for the reading operation is controlled by the [lua_socket_read_timeout](#lua_socket_read_timeout) config directive and the [settimeouts](#tcpsocksettimeouts) method. And the latter takes priority. For example:
7252
+
7253
+
```lua
7254
+
7255
+
sock:settimeouts(1000, 1000, 1000) -- one second timeout for connect/read/write
7256
+
localdata, err=sock:receiveany(10*1024*1024) -- read any data, at most 10K
7257
+
ifnotdatathen
7258
+
ngx.say("failed to read any data: ", err)
7259
+
return
7260
+
end
7261
+
ngx.say("successfully read: ", data)
7262
+
```
7263
+
7264
+
This method doesn't automatically close the current connection when the read timeout error occurs. For other connection errors, this method always automatically closes the connection.
7265
+
7266
+
This feature was first introduced in the `v0.10.14` release.
Returns any data received by the connected socket, at most <code>max</code> bytes.
6113
+
6114
+
This method is a synchronous operation just like the [[#tcpsock:send|send]] method and is 100% nonblocking.
6115
+
6116
+
In case of success, it returns the data received; in case of error, it returns <code>nil</code> with a string describing the error.
6117
+
6118
+
If the received data is more than this size, this method will return with exactly this size of data.
6119
+
The remaining data in the underlying receive buffer could be returned in the next reading operation.
6120
+
6121
+
Timeout for the reading operation is controlled by the [[#lua_socket_read_timeout|lua_socket_read_timeout]] config directive and the [[#tcpsock:settimeouts|settimeouts]] method. And the latter takes priority. For example:
6122
+
6123
+
<geshi lang="lua">
6124
+
sock:settimeouts(1000, 1000, 1000) -- one second timeout for connect/read/write
6125
+
local data, err = sock:receiveany(10 * 1024 * 1024) -- read any data, at most 10K
6126
+
if not data then
6127
+
ngx.say("failed to read any data: ", err)
6128
+
return
6129
+
end
6130
+
ngx.say("successfully read: ", data)
6131
+
</geshi>
6132
+
6133
+
This method doesn't automatically close the current connection when the read timeout error occurs. For other connection errors, this method always automatically closes the connection.
6134
+
6135
+
This feature was first introduced in the <code>v0.10.14</code> release.
0 commit comments