#ifndef UTILS_H
#define UTILS_H
#ifdef HAIKU_TARGET_PLATFORM_BEOS
# include <socket.h>
#else
# include <sys/socket.h>
# include <unistd.h>
#endif
#include <SupportDefs.h>
#include "Compatibility.h"
template<typename T> T max(const T& a, const T& b) { return (a > b ? a : b); }
template<typename T> T min(const T& a, const T& b) { return (a < b ? a : b); }
static inline
void
safe_closesocket(int32& socketVar)
{
int32 socket = atomic_or(&socketVar, -1);
#ifdef __HAIKU__
close(socket);
#else
if (socket >= 0) {
# ifndef HAIKU_TARGET_PLATFORM_BEOS
shutdown(socket, SHUTDOWN_BOTH);
# endif
closesocket(socket);
}
#endif
}
#endif