Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
msgq: dont block when fifo does not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Nov 19, 2019
1 parent b4b2678 commit bcad184
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions messaging/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void msgq_init_subscriber(msgq_queue_t * q) {
fsync(shm_fd);
close(shm_fd);

std::cout << "New subscriber id: " << q->reader_id << " uid: " << q->read_uid_local << std::endl;
std::cout << "New subscriber id: " << q->reader_id << " uid: " << q->read_uid_local << " " << q->endpoint << std::endl;
msgq_reset_reader(q);
}

Expand Down Expand Up @@ -315,13 +315,8 @@ int msgq_msg_send(msgq_msg_t * msg, msgq_queue_t *q){
std::string path = "/dev/shm/fifo-";
path += std::to_string(reader_uid);

while (true){
q->read_fifos[i] = open(path.c_str(), O_RDWR | O_NONBLOCK);
if(q->read_fifos[i] >= 0)
break;

// TODO: figure out why it sometimes takes multiple tries to open the fifo on ARM
// there is already an fsync on the containing dir, but the file is still not there
q->read_fifos[i] = open(path.c_str(), O_RDWR | O_NONBLOCK);
if(q->read_fifos[i] < 0){
std::cout << "Fifo: " << path << std::endl;
perror("Error opening fifo");
}
Expand All @@ -339,6 +334,7 @@ int msgq_get_fd(msgq_queue_t * q){
assert(id >= 0); // Make sure subscriber is initialized

if (q->read_uid_local != *q->read_uids[id]){
std::cout << q->endpoint << ": Reader was evicted, reconnecting" << std::endl;
msgq_init_subscriber(q);
}

Expand All @@ -352,6 +348,7 @@ int msgq_msg_ready(msgq_queue_t * q){
assert(id >= 0); // Make sure subscriber is initialized

if (q->read_uid_local != *q->read_uids[id]){
std::cout << q->endpoint << ": Reader was evicted, reconnecting" << std::endl;
msgq_init_subscriber(q);
goto start;
}
Expand All @@ -378,6 +375,7 @@ int msgq_msg_recv(msgq_msg_t * msg, msgq_queue_t * q){
assert(id >= 0); // Make sure subscriber is initialized

if (q->read_uid_local != *q->read_uids[id]){
std::cout << q->endpoint << ": Reader was evicted, reconnecting" << std::endl;
msgq_init_subscriber(q);
goto start;
}
Expand Down

0 comments on commit bcad184

Please sign in to comment.