Example #1
0
all_sigs_in_cache = (0.0, [])


def put_data(conn, data):
    if sys.hexversion > 0x3000000:
        data = data.encode('iso8859-1')
    cnt = 0
    while cnt < len(data):
        sent = conn.send(data[cnt:])
        if sent == 0:
            raise RuntimeError('connection ended')
        cnt += sent


push_connections = Runner.Queue(0)
pull_connections = Runner.Queue(0)


def get_connection(push=False):
    # return a new connection... do not forget to release it!
    try:
        if push:
            ret = push_connections.get(block=False)
        else:
            ret = pull_connections.get(block=False)
    except Exception:
        ret = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if push:
            ret.connect(Task.push_addr)
        else:
from waflib import Task, Logs, Utils, Build, Options, Runner
from waflib.Configure import conf

BUF = 8192 * 16
HEADER_SIZE = 128
MODES = ['PUSH', 'PULL', 'PUSH_PULL']
STALE_TIME = 30  # seconds

GET = 'GET'
PUT = 'PUT'
LST = 'LST'
BYE = 'BYE'

all_sigs_in_cache = (0.0, [])

active_connections = Runner.Queue(0)


def get_connection():
    # return a new connection... do not forget to release it!
    try:
        ret = active_connections.get(block=False)
    except Exception:
        ret = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ret.connect(Task.net_cache[:2])
    return ret


def release_connection(conn, msg=''):
    if conn:
        active_connections.put(conn)