cup.net.async package

Submodules

cup.net.async.common module

author:Guannan Ma
create_date:2014
last_date:2014
cup.net.async.common.ip_port2connaddr(peer)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数以peer(ipaddr, port)为输入参数, 生成一个connaddr

cup.net.async.common.add_stub2connaddr(pack, stub)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数设置connaddr中的stub到connaddr

cup.net.async.common.add_future2connaddr(pack, future)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数设置connaddr中的future到connaddr

cup.net.async.common.get_ip_and_port_connaddr(pack)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数获取connaddr中的(ip, port)

cup.net.async.common.getip_connaddr(pack)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数获取connaddr中的ip

cup.net.async.common.getport_connaddr(pack)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数获取connaddr中的port

cup.net.async.common.getstub_connaddr(pack)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数获取connaddr中的stub

cup.net.async.common.getfuture_connaddr(pack)[source]
connaddr是个64bit的int
32 - 16 - 16 - 32 ip - port - stub - future

该函数获取connaddr中的future

cup.net.async.conn module

author:Guannan Ma
create_date:2014
last_date:2014
descrition:connection related module
class cup.net.async.conn.CConnContext[source]

Bases: object

Connection上下文处理类

do_recv_data(data, data_len)[source]

push data into the recving_msg queue network read should be in 1 thread only.

get_context_info()[source]

get context info

get_peerinfo()[source]

get peerinfo

get_recving_msg()[source]

get the net msg being received

get_sock()[source]

return associated socket

is_detroying()[source]

is context being destroyed

is_reading()[source]

get if it is reading

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.

TODO:If the msg queue is too big, consider close the network link
release_readlock()[source]

release the readlock

release_writelock()[source]

release the writelock

set_conn_man(conn)[source]

set conn for context

set_peerinfo(peer)[source]

set peerinfo

set_reading(is_reading)[source]

set reading status

set_sock(sock)[source]

associate socket

to_destroy()[source]

destroy context

try_move2next_sending_msg()[source]

move to next msg that will be sent

try_readlock()[source]

try to acquire readlock

Returns:True if succeed. False, otherwise
try_writelock()[source]
Returns:True if succeed. False, otherwise
class cup.net.async.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: exceptions.Exception

internal queue error for CConnectionManager class

CConnectionManager.add_write_job(context)[source]

add network write into queue

CConnectionManager.bind()[source]

bind the ip:port

CConnectionManager.connect(peer)[source]
Parameters:peer – ip:port
CConnectionManager.dump_stats()[source]

dump stats

CConnectionManager.get_recv_msg()[source]

get recv msg from queue

CConnectionManager.get_recv_msg_ind()[source]

get recv msg ind

CConnectionManager.get_recv_queue()[source]

get recving_msg queue

CConnectionManager.poll()[source]

start to poll

CConnectionManager.push_msg2sendqueue(msg)[source]

push msg into the send queue

CConnectionManager.read(context)[source]

read with conn context

CConnectionManager.stop()[source]

stop the connection manager

cup.net.async.msg module

author:Guannan Ma
create_date:2014
last_date:2014
descrition:netmsg related module
class cup.net.async.msg.CNetMsg(is_postmsg=True)[source]

Bases: object

CNetMsg

flag: System use only. type: System will use type > 65535. Users will use type <=65535

#head 0, SAGIT for building connection #len - uint64 #fromip,port, stub -uint64 #toip,port, stub -uint64 #msg_type -uint32 #uniqid -uint64 #body -no limit (length:uint64)

MSGTYPE = <cup.net.async.msg.CMsgType object at 0x7f462e04e210>
MSG_FLAG_MAN = <cup.net.async.msg.CMsgFlag object at 0x7f462e04efd0>
MSG_SIGN = 'SAGIT0\\1'
get_body()[source]

get msg body

get_bodylen()[source]

get body length

get_flag()[source]

get msg flag

get_from_addr()[source]

get from addr

get_msg_len()[source]

get msg len

get_msg_type()[source]

get msg type

get_order_counts()[source]

get order counts

get_to_addr()[source]

get to addr

get_uniq_id()[source]

get unique msg id

get_write_bytes(length)[source]

get write bytes from the msg

is_a_recvmsg()[source]

is a msg being received

is_a_sendmsg()[source]

is a msg being sent

is_msg_already_sent()[source]

is msg already sent

is_recvmsg_complete()[source]

is msg received already

is_sendmsg_complete()[source]

is msg sent complete

push_data(data)[source]

push data into the msg

seek_write(length_ahead)[source]

seek foreward by length

set_body(body)[source]

set msg body

set_flag(flag)[source]

set flag for the msg

set_from_addr(ip_port, stub_future)[source]

set msg from addr

set_msg_type(msg_type)[source]

set msg type

set_need_head(b_need=False)[source]
Note:By default, the msg does not need to have a head unless it’s the first msg that posted/received.
set_to_addr(ip_port, stub_future)[source]

set msg to addr

set_uniq_id(uniq_id)[source]

set msg unique id

class cup.net.async.msg.CAckMsg(is_postmsg=True)[source]

Bases: cup.net.async.msg.CNetMsg

ack msg example

get_ack()[source]

get ack

set_ack(status, msg)[source]
Parameters:
  • status – status of the msg
  • msg
set_body(map_ack)[source]

set body

cup.net.async.msgcenter module

author:Guannan Ma
create_date:2014
last_date:2014
descrition:msg center related module
class cup.net.async.msgcenter.IMessageCenter(ip, port, thdpool_param=None, stat_intvl=20)[source]

Bases: object

Message center class

default_handle(msg)[source]

default handle for msgcenter

dump_stat()[source]

dump message center class

handle(msg)[source]

handle function which should be implemented by sub-class.

is_stopping()[source]

is msg center being stopped

post_msg(msg)[source]

post a net msg

run()[source]

run the msgcenter

setup()[source]

setup the message center

stop()[source]

stop the message center

Module contents

author:Guannan Ma
create_date:2014
last_date:2014
descrition:Async Module是ython tcp异步通讯框架.

Table Of Contents

Previous topic

cup.net package

Next topic

cup.res package

This Page