Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions msgq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def fake_event_handle(endpoint: str, identifier: Optional[str] = None, override:

return handle

def pub_sock(endpoint: str) -> PubSocket:
sock = PubSocket()
def pub_sock(endpoint: str, segment_size: int = 0) -> PubSocket:
sock = PubSocket(segment_size)
sock.connect(context, endpoint)
return sock

Expand Down
4 changes: 2 additions & 2 deletions msgq/impl_msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int MSGQSubSocket::connect(Context *context, std::string endpoint, std::string a
assert(address == "127.0.0.1");

q = new msgq_queue_t;
int r = msgq_new_queue(q, endpoint.c_str(), DEFAULT_SEGMENT_SIZE);
int r = msgq_new_queue(q, endpoint.c_str(), segment_size);
if (r != 0){
return r;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ int MSGQPubSocket::connect(Context *context, std::string endpoint, bool check_en
//}

q = new msgq_queue_t;
int r = msgq_new_queue(q, endpoint.c_str(), DEFAULT_SEGMENT_SIZE);
int r = msgq_new_queue(q, endpoint.c_str(), segment_size);
if (r != 0){
return r;
}
Expand Down
4 changes: 4 additions & 0 deletions msgq/impl_msgq.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class MSGQSubSocket : public SubSocket {
private:
msgq_queue_t * q = NULL;
int timeout;
size_t segment_size = DEFAULT_SEGMENT_SIZE;
public:
int connect(Context *context, std::string endpoint, std::string address, bool conflate=false, bool check_endpoint=true);
void setTimeout(int timeout);
void setSegmentSize(size_t size) { segment_size = size; }
void * getRawSocket() {return (void*)q;}
Message *receive(bool non_blocking=false);
~MSGQSubSocket();
Expand All @@ -46,7 +48,9 @@ class MSGQSubSocket : public SubSocket {
class MSGQPubSocket : public PubSocket {
private:
msgq_queue_t * q = NULL;
size_t segment_size;
public:
MSGQPubSocket(size_t size = 0) : segment_size(size ? size : DEFAULT_SEGMENT_SIZE) {}
int connect(Context *context, std::string endpoint, bool check_endpoint=true);
int sendMessage(Message *message);
int send(char *data, size_t size);
Expand Down
1 change: 1 addition & 0 deletions msgq/impl_zmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ZMQPubSocket : public PubSocket {
std::string full_endpoint;
int pid = -1;
public:
ZMQPubSocket(size_t size = 0) { (void)size; } // size ignored for ZMQ
int connect(Context *context, std::string endpoint, bool check_endpoint=true);
int sendMessage(Message *message);
int send(char *data, size_t size);
Expand Down
10 changes: 5 additions & 5 deletions msgq/ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ SubSocket * SubSocket::create(Context * context, std::string endpoint, std::stri
}
}

PubSocket * PubSocket::create(){
PubSocket * PubSocket::create(size_t segment_size){
PubSocket * s;
if (messaging_use_zmq()){
s = new ZMQPubSocket();
s = new ZMQPubSocket(segment_size);
} else {
s = new MSGQPubSocket();
s = new MSGQPubSocket(segment_size);
}

return s;
}

PubSocket * PubSocket::create(Context * context, std::string endpoint, bool check_endpoint){
PubSocket *s = PubSocket::create();
PubSocket * PubSocket::create(Context * context, std::string endpoint, bool check_endpoint, size_t segment_size){
PubSocket *s = PubSocket::create(segment_size);
int r = s->connect(context, endpoint, check_endpoint);

if (r == 0) {
Expand Down
5 changes: 2 additions & 3 deletions msgq/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class PubSocket {
virtual int sendMessage(Message *message) = 0;
virtual int send(char *data, size_t size) = 0;
virtual bool all_readers_updated() = 0;
static PubSocket * create();
static PubSocket * create(Context * context, std::string endpoint, bool check_endpoint=true);
static PubSocket * create(Context * context, std::string endpoint, int port, bool check_endpoint=true);
static PubSocket * create(size_t segment_size = 0);
static PubSocket * create(Context * context, std::string endpoint, bool check_endpoint=true, size_t segment_size=0);
virtual ~PubSocket(){}
};

Expand Down
2 changes: 1 addition & 1 deletion msgq/ipc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cdef extern from "msgq/ipc.h":

cdef cppclass PubSocket:
@staticmethod
PubSocket * create()
PubSocket * create(size_t)
int connect(Context *, string)
int sendMessage(Message *)
int send(char *, size_t)
Expand Down
4 changes: 2 additions & 2 deletions msgq/ipc_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ cdef class SubSocket:
cdef class PubSocket:
cdef cppPubSocket * socket

def __cinit__(self):
self.socket = cppPubSocket.create()
def __cinit__(self, size_t segment_size=0):
self.socket = cppPubSocket.create(segment_size)
if self.socket == NULL:
raise IpcError

Expand Down
Loading