diff options
| author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-09-17 15:06:08 +0200 | 
|---|---|---|
| committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-09-17 15:06:08 +0200 | 
| commit | e2edbaeee5d593a24bc97d8210e9a0d525996274 (patch) | |
| tree | c573338cfa37da9c3b8f807670715ebaf7dfeb03 /src/StatsPublish.cpp | |
| parent | eb1182eb8760131c591f6b8932a8694849c18e3c (diff) | |
| parent | 33706e0aea432bafe6b2f49e248192b595761f82 (diff) | |
| download | ODR-SourceCompanion-e2edbaeee5d593a24bc97d8210e9a0d525996274.tar.gz ODR-SourceCompanion-e2edbaeee5d593a24bc97d8210e9a0d525996274.tar.bz2 ODR-SourceCompanion-e2edbaeee5d593a24bc97d8210e9a0d525996274.zip | |
Merge branch 'next' into padsocket
Diffstat (limited to 'src/StatsPublish.cpp')
| -rw-r--r-- | src/StatsPublish.cpp | 22 | 
1 files changed, 17 insertions, 5 deletions
| diff --git a/src/StatsPublish.cpp b/src/StatsPublish.cpp index cdb32cb..5998913 100644 --- a/src/StatsPublish.cpp +++ b/src/StatsPublish.cpp @@ -1,5 +1,5 @@  /* ------------------------------------------------------------------ - * Copyright (C) 2019 Matthias P. Braendli + * Copyright (C) 2020 Matthias P. Braendli   *   * Licensed under the Apache License, Version 2.0 (the "License");   * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@  #include <sys/socket.h>  #include <sys/un.h>  #include <unistd.h> +#include <fcntl.h>  using namespace std; @@ -35,17 +36,28 @@ StatsPublisher::StatsPublisher(const string& socket_path) :      // The client socket binds to a socket whose name depends on PID, and connects to      // `socket_path` -    m_sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0); +    m_sock = ::socket(AF_UNIX, SOCK_DGRAM, 0);      if (m_sock == -1) {          throw runtime_error("Stats socket creation failed: " + string(strerror(errno)));      } +    int flags = fcntl(m_sock, F_GETFL); +    if (flags == -1) { +        std::string errstr(strerror(errno)); +        throw std::runtime_error("Stats socket: Could not get socket flags: " + errstr); +    } + +    if (fcntl(m_sock, F_SETFL, flags | O_NONBLOCK) == -1) { +        std::string errstr(strerror(errno)); +        throw std::runtime_error("Stats socket: Could not set O_NONBLOCK: " + errstr); +    } +      struct sockaddr_un claddr;      memset(&claddr, 0, sizeof(struct sockaddr_un));      claddr.sun_family = AF_UNIX;      snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/odr-audioenc.%ld", (long) getpid()); -    int ret = bind(m_sock, (const struct sockaddr *) &claddr, sizeof(struct sockaddr_un)); +    int ret = ::bind(m_sock, (const struct sockaddr *) &claddr, sizeof(struct sockaddr_un));      if (ret == -1) {          throw runtime_error("Stats socket bind failed " + string(strerror(errno)));      } @@ -54,7 +66,7 @@ StatsPublisher::StatsPublisher(const string& socket_path) :  StatsPublisher::~StatsPublisher()  {      if (m_sock != -1) { -        close(m_sock); +        ::close(m_sock);      }  } @@ -97,7 +109,7 @@ void StatsPublisher::send_stats()      claddr.sun_family = AF_UNIX;      snprintf(claddr.sun_path, sizeof(claddr.sun_path), "%s", m_socket_path.c_str()); -    int ret = sendto(m_sock, yamlstr.data(), yamlstr.size(), 0, +    int ret = ::sendto(m_sock, yamlstr.data(), yamlstr.size(), 0,              (struct sockaddr *) &claddr, sizeof(struct sockaddr_un));      if (ret == -1) {          // This suppresses the -Wlogical-op warning | 
