cup.net.asyn package¶
- description:
Async Module is a tcp framework for asynchrous network msg tranfering
Submodules¶
cup.net.asyn.common module¶
common function module for cup.net.asyn
cup.net.asyn.conn module¶
- description:
connection related module 1. There’s only 1 thread reading/receiving data from the interface. 2. There might have more than 1 thred writing data into the network
queue. 1 thread per context(ip, port).
Notice that _do_write will only TRY to send out some data. It might encounter TCP/IP stack full of data in the SEND buffer-queue of the network interface
- class cup.net.asyn.conn.CConnectionManager(ip, bindport, thdpool_param)[source]¶
Bases:
object
connaddr. Convert ip:port into a 64-bit hex.
- NET_RW_SIZE = 131072¶
- exception QueueError(msg)[source]¶
Bases:
Exception
internal queue error for CConnectionManager class
- SOCK_ALIVE_PARAMS = {'after_idle_sec': 1, 'interval_sec': 3, 'max_fails': 5}¶
- global_sock_keepalive(after_idle_sec=1, interval_sec=3, max_fails=5)[source]¶
Set TCP keepalive on an open socket. It activates after 1 second (after_idle_sec) of idleness, then sends a keepalive ping once every 3 seconds (interval_sec), and closes the connection after 5 failed ping (max_fails), or 15 sec Notice, this will set all sockets this way. :param sock:
socket
- Parameters:
after_idle_sec – for TCP_KEEPIDLE. May not work, depends on ur system
interval_sec – for TCP_KEEPINTVL
max_fails – for TCP_KEEPCNT
cup.net.asyn.context module¶
- description:
Connection Context for each socket
- class cup.net.asyn.context.CConnContext[source]¶
Bases:
object
connection context for each socket
- CONTEXT_QUEUE_SIZE = 200¶
- do_recv_data(data, data_len)[source]¶
push data into the recving_msg queue network read should be in 1 thread only.
- put_msg(flag, msg)[source]¶
Put msg into the sending queue.
- Parameters:
flag –
flag determines the priority of the msg.
Msg with higher priority will have bigger chance to be
sent out soon.
return – return 0 on success return 1 on TRY_AGAIN —- queue is full. network is too busy.
- TODO:
If the msg queue is too big, consider close the network link
cup.net.asyn.ioloop module¶
- description:
pollers for epoll and kqueue and others. Refer IOLoop from tornado:
Respect to the tornado team:
Tornado is based on Apache V2.0 License. Here it goes:
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- class cup.net.asyn.ioloop.Epoller[source]¶
Bases:
BasePoller
epoll for linux and others
- class cup.net.asyn.ioloop.KQueuePoller[source]¶
Bases:
BasePoller
kqueue for macos
cup.net.asyn.msg module¶
- description:
netmsg related module
- class cup.net.asyn.msg.CNetMsg(is_postmsg=True)[source]¶
Bases:
object
flag: System use only. type: System will use type > 65535. Users will use type <=65535
#head CUP012-3 for building connection #len - uint64 #fromip,port, stub -uint64 #toip,port, stub -uint64 #msg_type -uint32 #uniqid -128bit [64bit ip, port, 64 bit, uniqid] #body -no limit (length:uint64)
- MSGTYPE = <cup.net.asyn.msg.CMsgType object>¶
- MSG_FLAG_MAN = <cup.net.asyn.msg.CMsgFlag object>¶
- MSG_SIGN = 'CUP012-3'¶
- get_body(return_unicode=False)[source]¶
get msg body
- Parameters:
return_unicode – False by default, return str (in py2), bytes in py3. Return unicode if return_unicode is True
- push_data(data)[source]¶
push data into the msg. Return pushed length.
Return -1 if we should shutdown the socket channel.
- Raises:
exception – may raise IndexError when coming msg has problems.
cup.net.asyn.msgcenter module¶
- descrition:
msg center related module
- class cup.net.asyn.msgcenter.IMessageCenter(ip, port, thdpool_param=None, stat_intvl=20)[source]¶
Bases:
object
Message center class
- global_sock_keepalive(after_idle_sec=1, interval_sec=3, max_fails=5)[source]¶
Set TCP keepalive on an open socket. It activates after 1 second (after_idle_sec) of idleness, then sends a keepalive ping once every 3 seconds (interval_sec), and closes the connection after 5 failed ping (max_fails), or 15 sec
Notice, this will set all sockets this way.
- Parameters:
sock – socket
after_idle_sec – for TCP_KEEPIDLE. May not work, depends on ur system
interval_sec – for TCP_KEEPINTVL
max_fails – for TCP_KEEPCNT