#ifndef _VIP_VIPDEFS_HH_
#define _VIP_VIPDEFS_HH_

#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>

# ifdef VIP_EXPORTS
#  define VIP_API __declspec(dllexport)
# else
#  define VIP_API __declspec(dllimport)
# endif
#else
# ifdef HAVE_GCC_VISIBILITY
#  define VIP_API __attribute__ ((visibility("default")))
# else
#  define VIP_API
# endif
#endif

#if defined(_WIN32) && defined(_MSC_VER)
# include <vos/vosconfig-vc7.h>
#elif defined(DEVCPP)
# include <vos/vosconfig-devc++.h>
#else
# include <vos/vosconfig.h>
#endif

#define VIP_DATA  1
#define VIP_SYN   2
#define VIP_RST   4
#define VIP_PING  8

#define VIP_CONNECT_WAIT_TIME  4  // seconds between SYN attempts
#define VIP_PING_WAIT_TIME     4  // seconds between PING attempts

// Seconds without any activity (inc. pings) before disconnecting
#define VIP_CONNECTION_TIMEOUT 60

#define VIP_MAXPKTSIZE 1350 // bytes

// seconds to continue using LLP scheduling without any outgoing LLP data
#define VIP_LLP_SLACK 10

// Protocol identifiers/indexes
#define VIP_LOWLATENCY 0
#define VIP_STDPROTO   4

#define VIP_PROTOSLOTS 16

#define VIP_STDPROTO_CHANNELS 16

// VIP_SEQWIN is defined in stdprotocol.cc and lowlatencyproto.cc (differently in each!)

#define VIP_INWIN(X) ((X) < VIP_SEQWIN || (X) > (0xFFFFFFFF-VIP_SEQWIN))

#define VIP_SEQNUMLT(X, Y)   ((VIP_INWIN(X) || VIP_INWIN(Y)) ? (((X)+VIP_SEQWIN) < ((Y)+VIP_SEQWIN)) : (X < Y))
#define VIP_SEQNUMLTE(X, Y)  ((VIP_INWIN(X) || VIP_INWIN(Y)) ? (((X)+VIP_SEQWIN) <= ((Y)+VIP_SEQWIN)) : (X <= Y))
#define VIP_SEQNUMGT(X, Y)   VIP_SEQNUMLT(Y, X)
#define VIP_SEQNUMGTE(X, Y)  VIP_SEQNUMLTE(Y, X)

#define VIP_SEQNUMDIFF(X, Y) ((X) < VIP_SEQWIN && (Y) > (0xFFFFFFFF-VIP_SEQWIN) \
                          ? (((X)+VIP_SEQWIN) - ((Y)+VIP_SEQWIN)) : (X) - (Y))

#endif
