| #include <sys/socket.h> |
| #include <unistd.h> |
| |
| #include <sdeventplus/event.hpp> |
| #include <stdplus/print.hpp> |
| #include <util/matcher/rde_match_handler.hpp> |
| #include <util/resource_id_mapper.hpp> |
| |
| #include <cstddef> |
| #include <string> |
| |
| constexpr int SOCKET_TIMEOUT_SECONDS = 8; |
| |
| void setSocketTimeout(int fd, int seconds, int milliseconds) |
| { |
| struct timeval tv; |
| tv.tv_sec = seconds; |
| tv.tv_usec = milliseconds; |
| setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv); |
| } |
| |
| int main() |
| { |
| stdplus::print(stderr, "Successfully started the RDE Daemon \n"); |
| int fd = socket(AF_MCTP, SOCK_DGRAM, 0); |
| if (fd == -1) |
| { |
| stdplus::print(stderr, "Created socket Failed\n"); |
| return fd; |
| } |
| |
| stdplus::print(stderr, "Socket Created with ID: {}. Setting timeouts...\n", |
| fd); |
| setSocketTimeout(fd, /*seconds=*/SOCKET_TIMEOUT_SECONDS, |
| /*milliseconds=*/0); |
| |
| socklen_t optLen; |
| int currentSendBuffSize; |
| optLen = sizeof(currentSendBuffSize); |
| int res = |
| getsockopt(fd, SOL_SOCKET, SO_SNDBUF, ¤tSendBuffSize, &optLen); |
| if (res == -1) |
| { |
| stdplus::print( |
| stderr, |
| "Error in obtaining the default send buffer size, Error: {}\n", |
| strerror(errno)); |
| return -1; |
| } |
| |
| RdeMatchHandler matcher(fd); |
| matcher.triggerMatcher(); |
| stdplus::print(stderr, "RDE Reactor stopped...\n"); |
| |
| // Daemon loop -- Code never reaches here if the reactor is running fine |
| sdeventplus::Event event = sdeventplus::Event::get_default(); |
| int rc = event.loop(); |
| if (rc) |
| { |
| exit(EXIT_FAILURE); |
| } |
| exit(EXIT_SUCCESS); |
| } |