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
This function is added for [LuaSocket](http://w3.impa.br/~diego/software/luasocket/tcp.html) API compatibility and does nothing for now. Its functionality will be implemented in future.
7796
+
This function is added for [LuaSocket](http://w3.impa.br/~diego/software/luasocket/tcp.html) API compatibility and does nothing for now. Its functionality is implemented `v0.10.18`.
7797
7797
7798
7798
This feature was first introduced in the `v0.5.0rc1` release.
7799
7799
7800
+
In case of success, it returns `true`. Otherwise, it returns nil and a string describing the error.
7801
+
7802
+
The `option` is a string with the option name, and the value depends on the option being set:
7803
+
7804
+
*`keepalive`
7805
+
7806
+
Setting this option to true enables sending of keep-alive messages on
7807
+
connection-oriented sockets. Make sure the `connect` function
7808
+
had been called before, for example,
7809
+
7810
+
```lua
7811
+
7812
+
local ok, err = tcpsock:setoption("keepalive", true)
7813
+
if not ok then
7814
+
ngx.say("setoption keepalive failed: ", err)
7815
+
end
7816
+
```
7817
+
*`reuseaddr`
7818
+
7819
+
Enabling this option indicates that the rules used in validating addresses
7820
+
supplied in a call to bind should allow reuse of local addresses. Make sure
7821
+
the `connect` function had been called before, for example,
7822
+
7823
+
```lua
7824
+
7825
+
local ok, err = tcpsock:setoption("reuseaddr", 0)
7826
+
if not ok then
7827
+
ngx.say("setoption reuseaddr failed: ", err)
7828
+
end
7829
+
```
7830
+
*`tcp-nodelay`
7831
+
7832
+
Setting this option to true disables the Nagle's algorithm for the connection.
7833
+
Make sure the `connect` function had been called before, for example,
7834
+
7835
+
```lua
7836
+
7837
+
local ok, err = tcpsock:setoption("tcp-nodelay", true)
7838
+
if not ok then
7839
+
ngx.say("setoption tcp-nodelay failed: ", err)
7840
+
end
7841
+
```
7842
+
*`sndbuf`
7843
+
7844
+
Sets the maximum socket send buffer in bytes. The kernel doubles this value
7845
+
(to allow space for bookkeeping overhead) when it is set using setsockopt().
7846
+
Make sure the `connect` function had been called before, for example,
7847
+
7848
+
```lua
7849
+
7850
+
local ok, err = tcpsock:setoption("sndbuf", 1024 * 10)
7851
+
if not ok then
7852
+
ngx.say("setoption sndbuf failed: ", err)
7853
+
end
7854
+
```
7855
+
*`rcvbuf`
7856
+
7857
+
Sets the maximum socket receive buffer in bytes. The kernel doubles this value
7858
+
(to allow space for bookkeeping overhead) when it is set using setsockopt. Make
7859
+
sure the `connect` function had been called before, for example,
7860
+
7861
+
```lua
7862
+
7863
+
local ok, err = tcpsock:setoption("rcvbuf", 1024 * 10)
7864
+
if not ok then
7865
+
ngx.say("setoption rcvbuf failed: ", err)
7866
+
end
7867
+
```
7868
+
7869
+
NOTE: Once the option is set, it will become effective until the connection is closed. If you know the connection is from the connection pool and all the in-pool connections already have called the setoption() method with the desired socket option state, then you can just skip calling setoption() again to avoid the overhead of repeated calls, for example,
7870
+
7871
+
```lua
7872
+
7873
+
localcount, err=tcpsock:getreusedtimes()
7874
+
ifnotcountthen
7875
+
ngx.say("getreusedtimes failed: ", err)
7876
+
return
7877
+
end
7878
+
7879
+
ifcount==0then
7880
+
localok, err=tcpsock:setoption("rcvbuf", 1024*10)
7881
+
ifnotokthen
7882
+
ngx.say("setoption rcvbuf failed: ", err)
7883
+
return
7884
+
end
7885
+
end
7886
+
```
7887
+
7888
+
These options described above are supported in `v0.10.18`, and more options will be implemented in future.
This function is added for [http://w3.impa.br/~diego/software/luasocket/tcp.html LuaSocket] API compatibility and does nothing for now. Its functionality will be implemented in future.
6633
+
This function is added for [http://w3.impa.br/~diego/software/luasocket/tcp.html LuaSocket] API compatibility and does nothing for now. Its functionality is implemented <code>v0.10.18</code>.
6634
6634
6635
6635
This feature was first introduced in the <code>v0.5.0rc1</code> release.
6636
6636
6637
+
In case of success, it returns <code>true</code>. Otherwise, it returns nil and a string describing the error.
6638
+
6639
+
The <code>option</code> is a string with the option name, and the value depends on the option being set:
6640
+
6641
+
* <code>keepalive</code>
6642
+
6643
+
: Setting this option to true enables sending of keep-alive messages on
6644
+
: connection-oriented sockets. Make sure the <code>connect</code> function
6645
+
: had been called before, for example,
6646
+
6647
+
<geshi lang="lua">
6648
+
local ok, err = tcpsock:setoption("keepalive", true)
6649
+
if not ok then
6650
+
ngx.say("setoption keepalive failed: ", err)
6651
+
end
6652
+
</geshi>
6653
+
* <code>reuseaddr</code>
6654
+
6655
+
: Enabling this option indicates that the rules used in validating addresses
6656
+
: supplied in a call to bind should allow reuse of local addresses. Make sure
6657
+
: the <code>connect</code> function had been called before, for example,
6658
+
6659
+
<geshi lang="lua">
6660
+
local ok, err = tcpsock:setoption("reuseaddr", 0)
6661
+
if not ok then
6662
+
ngx.say("setoption reuseaddr failed: ", err)
6663
+
end
6664
+
</geshi>
6665
+
* <code>tcp-nodelay</code>
6666
+
6667
+
: Setting this option to true disables the Nagle's algorithm for the connection.
6668
+
: Make sure the <code>connect</code> function had been called before, for example,
6669
+
6670
+
<geshi lang="lua">
6671
+
local ok, err = tcpsock:setoption("tcp-nodelay", true)
6672
+
if not ok then
6673
+
ngx.say("setoption tcp-nodelay failed: ", err)
6674
+
end
6675
+
</geshi>
6676
+
* <code>sndbuf</code>
6677
+
6678
+
: Sets the maximum socket send buffer in bytes. The kernel doubles this value
6679
+
: (to allow space for bookkeeping overhead) when it is set using setsockopt().
6680
+
: Make sure the <code>connect</code> function had been called before, for example,
6681
+
6682
+
<geshi lang="lua">
6683
+
local ok, err = tcpsock:setoption("sndbuf", 1024 * 10)
6684
+
if not ok then
6685
+
ngx.say("setoption sndbuf failed: ", err)
6686
+
end
6687
+
</geshi>
6688
+
* <code>rcvbuf</code>
6689
+
6690
+
: Sets the maximum socket receive buffer in bytes. The kernel doubles this value
6691
+
: (to allow space for bookkeeping overhead) when it is set using setsockopt. Make
6692
+
: sure the <code>connect</code> function had been called before, for example,
6693
+
6694
+
<geshi lang="lua">
6695
+
local ok, err = tcpsock:setoption("rcvbuf", 1024 * 10)
6696
+
if not ok then
6697
+
ngx.say("setoption rcvbuf failed: ", err)
6698
+
end
6699
+
</geshi>
6700
+
6701
+
NOTE: Once the option is set, it will become effective until the connection is closed. If you know the connection is from the connection pool and all the in-pool connections already have called the setoption() method with the desired socket option state, then you can just skip calling setoption() again to avoid the overhead of repeated calls, for example,
6702
+
6703
+
<geshi lang="lua">
6704
+
local count, err = tcpsock:getreusedtimes()
6705
+
if not count then
6706
+
ngx.say("getreusedtimes failed: ", err)
6707
+
return
6708
+
end
6709
+
6710
+
if count == 0 then
6711
+
local ok, err = tcpsock:setoption("rcvbuf", 1024 * 10)
6712
+
if not ok then
6713
+
ngx.say("setoption rcvbuf failed: ", err)
6714
+
return
6715
+
end
6716
+
end
6717
+
</geshi>
6718
+
6719
+
These options described above are supported in <code>v0.10.18</code>, and more options will be implemented in future.
0 commit comments