def __init__(self, factory, *endpoints): """ Constructor. @param factory: ZeroMQ Twisted factory @type factory: L{ZmqFactory} @param endpoints: ZeroMQ addresses for connect/bind @type endpoints: C{list} of L{ZmqEndpoint} """ self.factory = factory self.endpoints = endpoints self.socket = Socket(factory.context, self.socketType) self.queue = deque() self.recv_parts = [] self.fd = self.socket.getsockopt(constants.FD) self.socket.setsockopt(constants.LINGER, factory.lingerPeriod) self.socket.setsockopt(constants.MCAST_LOOP, int(self.allowLoopbackMulticast)) self.socket.setsockopt(constants.RATE, self.multicastRate) self.socket.setsockopt(constants.HWM, self.highWaterMark) if self.identity is not None: self.socket.setsockopt(constants.IDENTITY, self.identity) self._connectOrBind() self.factory.connections.add(self) self.factory.reactor.addReader(self)
def __init__(self, factory, endpoint=None, identity=None): """ Constructor. One endpoint is passed to the constructor, more could be added via call to C{addEndpoints}. @param factory: ZeroMQ Twisted factory @type factory: L{ZmqFactory} @param endpoint: ZeroMQ address for connect/bind @type endpoint: C{list} of L{ZmqEndpoint} @param identity: socket identity (ZeroMQ) @type identity: C{str} """ self.factory = factory self.endpoints = [] self.identity = identity self.socket = Socket(factory.context, self.socketType) self.queue = deque() self.recv_parts = [] self.read_scheduled = None self.fd = self.socket_get(constants.FD) self.socket_set(constants.LINGER, factory.lingerPeriod) if not ZMQ3: self.socket_set( constants.MCAST_LOOP, int(self.allowLoopbackMulticast)) self.socket_set(constants.RATE, self.multicastRate) if not ZMQ3: self.socket_set(constants.HWM, self.highWaterMark) else: self.socket_set(constants.SNDHWM, self.highWaterMark) self.socket_set(constants.RCVHWM, self.highWaterMark) if ZMQ3 and self.tcpKeepalive: self.socket_set( constants.TCP_KEEPALIVE, self.tcpKeepalive) self.socket_set( constants.TCP_KEEPALIVE_CNT, self.tcpKeepaliveCount) self.socket_set( constants.TCP_KEEPALIVE_IDLE, self.tcpKeepaliveIdle) self.socket_set( constants.TCP_KEEPALIVE_INTVL, self.tcpKeepaliveInterval) if self.identity is not None: self.socket_set(constants.IDENTITY, self.identity) if endpoint: self.addEndpoints([endpoint]) self.factory.connections.add(self) self.factory.reactor.addReader(self) self.doRead()
def _createSocket(self, factory): """ Create a socket and assign the fd. """ socket = Socket(factory.context, self.socketType) self.fd = socket.getsockopt(constants.FD) socket.setsockopt(constants.LINGER, factory.lingerPeriod) socket.setsockopt(constants.MCAST_LOOP, int(self.allowLoopbackMulticast)) socket.setsockopt(constants.RATE, self.multicastRate) socket.setsockopt(constants.HWM, self.highWaterMark) if self.identity is not None: socket.setsockopt(constants.IDENTITY, self.identity) return socket
def __init__(self, socketType=None): """ @param context: Context this socket is to be associated with @type factory: L{ZmqFactory} @param socketType: Type of socket to create @type socketType: C{int} """ if socketType is not None: self.socketType = socketType assert self.socketType is not None self._ctx = getContext() self._zsock = Socket(getContext()._zctx, self.socketType) self._queue = deque() self.fd = self._zsock.getsockopt(constants.FD) self._ctx._sockets.add(self) self._ctx.reactor.addReader(self)