Skip to content

Commit

Permalink
Add openbsd defines to enable build on openbsd
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor authored and Isaac Connor committed Sep 11, 2023
1 parent f7731d7 commit 81c9aba
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/net/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#ifndef XOP_SOCKET_H
#define XOP_SOCKET_H

#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined (__OpenBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#if 0
#include <net/ethernet.h>
#endif
#include <net/route.h>
#include <netdb.h>
#include <net/if.h>
Expand Down
8 changes: 4 additions & 4 deletions src/net/SocketUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool SocketUtil::Bind(SOCKET sockfd, std::string ip, uint16_t port)

void SocketUtil::SetNonBlock(SOCKET fd)
{
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
#elif defined(WIN32) || defined(_WIN32)
Expand All @@ -34,7 +34,7 @@ void SocketUtil::SetNonBlock(SOCKET fd)

void SocketUtil::SetBlock(SOCKET fd, int write_timeout)
{
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags&(~O_NONBLOCK));
#elif defined(WIN32) || defined(_WIN32)
Expand All @@ -45,7 +45,7 @@ void SocketUtil::SetBlock(SOCKET fd, int write_timeout)
if(write_timeout > 0)
{
#ifdef SO_SNDTIMEO
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
struct timeval tv = {write_timeout/1000, (write_timeout%1000)*1000};
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&tv, sizeof tv);
#elif defined(WIN32) || defined(_WIN32)
Expand Down Expand Up @@ -168,7 +168,7 @@ int SocketUtil::GetPeerAddr(SOCKET sockfd, struct sockaddr_in *addr)

void SocketUtil::Close(SOCKET sockfd)
{
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
::close(sockfd);
#elif defined(WIN32) || defined(_WIN32)
::closesocket(sockfd);
Expand Down
4 changes: 2 additions & 2 deletions src/net/TaskScheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "TaskScheduler.h"
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <signal.h>
#endif

Expand Down Expand Up @@ -36,7 +36,7 @@ TaskScheduler::~TaskScheduler()
void TaskScheduler::Start()
{
#if 0
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
signal(SIGPIPE, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGUSR1, SIG_IGN);
Expand Down
2 changes: 1 addition & 1 deletion src/net/TcpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool TcpSocket::Connect(std::string ip, uint16_t port, int timeout)

void TcpSocket::Close()
{
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
::close(sockfd_);
#elif defined(WIN32) || defined(_WIN32)
closesocket(sockfd_);
Expand Down
4 changes: 2 additions & 2 deletions src/net/Timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ std::string Timestamp::Localtime()
struct tm tm;
localtime_s(&tm, &tt);
stream << std::put_time(&tm, "%F %T");
#elif defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#elif defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
char buffer[200] = {0};
std::string timeString;
std::strftime(buffer, 200, "%F %T", std::localtime(&tt));
stream << buffer;
#endif
return stream.str();
}
}
4 changes: 2 additions & 2 deletions src/xop/rtsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class Rtsp : public std::enable_shared_from_this<Rtsp>
char ip[100] = { 0 };
char suffix[100] = { 0 };
uint16_t port = 0;
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
if (sscanf(url.c_str() + 7, "%[^:]:%hu/%s", ip, &port, suffix) == 3)
#elif defined(WIN32) || defined(_WIN32)
if (sscanf_s(url.c_str() + 7, "%[^:]:%hu/%s", ip, 100, &port, suffix, 100) == 3)
#endif
{
rtsp_url_info_.port = port;
}
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
else if (sscanf(url.c_str() + 7, "%[^/]/%s", ip, suffix) == 2)
#elif defined(WIN32) || defined(_WIN32)
else if (sscanf_s(url.c_str() + 7, "%[^/]/%s", ip, 100, suffix, 100) == 2)
Expand Down

0 comments on commit 81c9aba

Please sign in to comment.