Пример #1
0
def stream_socket_accept(interp, w_res, timeout=-1, w_ref_peer=None):
    """ Accept a connection on a socket created by stream_socket_server"""
    space = interp.space
    fd, addr = w_res.accept()
    w_res = W_SocketResource(space, None, -1, fd=fd)
    if timeout == -1:
        w_timeout = interp.config.get_ini_w('default_socket_timeout')
        timeout = interp.space.float_w(w_timeout)
    w_res.settimeout(timeout)
    return w_res
Пример #2
0
def stream_socket_accept(interp, w_res, timeout=-1, w_ref_peer=None):
    """ Accept a connection on a socket created by stream_socket_server"""
    space = interp.space
    fd, addr = w_res.accept()
    w_res = W_SocketResource(space, None, -1, fd=fd)
    if timeout == -1:
        w_timeout = interp.config.get_ini_w('default_socket_timeout')
        timeout = interp.space.float_w(w_timeout)
    w_res.settimeout(timeout)
    return w_res
Пример #3
0
def fsockopen(interp,
              hostname,
              port=-1,
              w_ref_errno=None,
              w_ref_errstr=None,
              timeout=-1):
    """ Open Internet or Unix domain socket connection"""
    space = interp.space
    r = urlsplit(hostname)
    host = r.host
    if not host:
        host = r.path
    if port == -1:
        port = r.port
    type = 'tcp'
    if r.scheme:
        type = r.scheme
    cstring = "%s://%s:%d" % (type, host, port)
    if type not in ['tcp', 'udp']:
        s = 'Unable to find the socket transport "%s" - did you forget to enable it when you configured PHP?'
        out = s % type
        if w_ref_errstr is not None:
            w_ref_errstr.store(space.wrap(out))
        space.ec.warn("fsockopen(): unable to connect to %s (%s)" %
                      (cstring, out))
        return space.w_False
    w_res = W_SocketResource(space, host, port, type)
    if timeout == -1:
        w_timeout = interp.config.get_ini_w('default_socket_timeout')
        timeout = interp.space.float_w(w_timeout)
    w_res.open()
    w_res.settimeout(timeout)
    if w_ref_errno is not None:
        w_ref_errno.store(space.wrap(w_res.errno))
    if w_ref_errstr is not None:
        w_ref_errstr.store(space.wrap(w_res.errstr))
    if w_res.errno != 0:
        space.ec.warn("fsockopen(): unable to connect to %s (%s)" %
                      (cstring, w_res.errstr))
        return space.w_False
    return w_res
Пример #4
0
def fsockopen(interp, hostname, port=-1, w_ref_errno=None,
              w_ref_errstr=None, timeout=-1):
    """ Open Internet or Unix domain socket connection"""
    space = interp.space
    r = urlsplit(hostname)
    host = r.host
    if not host:
        host = r.path
    if port == -1:
        port = r.port
    type = 'tcp'
    if r.scheme:
        type = r.scheme
    cstring = "%s://%s:%d" % (type, host, port)
    if type not in ['tcp', 'udp']:
        s = 'Unable to find the socket transport "%s" - did you forget to enable it when you configured PHP?'
        out = s % type
        if w_ref_errstr is not None:
            w_ref_errstr.store(space.wrap(out))
        space.ec.warn("fsockopen(): unable to connect to %s (%s)" % (cstring, out))
        return space.w_False
    w_res = W_SocketResource(space, host, port, type)
    if timeout == -1:
        w_timeout = interp.config.get_ini_w('default_socket_timeout')
        timeout = interp.space.float_w(w_timeout)
    w_res.open()
    w_res.settimeout(timeout)
    if w_ref_errno is not None:
        w_ref_errno.store(space.wrap(w_res.errno))
    if w_ref_errstr is not None:
        w_ref_errstr.store(space.wrap(w_res.errstr))
    if w_res.errno != 0:
        space.ec.warn("fsockopen(): unable to connect to %s (%s)" %
                      (cstring, w_res.errstr))
        return space.w_False
    return w_res