fixes issues for Linux compilation

This commit is contained in:
Volker Fischer 2014-02-11 20:39:07 +00:00
parent a9c0e243dd
commit 7c37d6d018
2 changed files with 19 additions and 9 deletions

View file

@ -57,7 +57,7 @@ void CSocket::Init ( const quint16 iPortNumber )
#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD #ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
// preinitialize socket in address (only the port number is missing) // preinitialize socket in address (only the port number is missing)
SOCKADDR_IN UdpSocketInAddr; sockaddr_in UdpSocketInAddr;
UdpSocketInAddr.sin_family = AF_INET; UdpSocketInAddr.sin_family = AF_INET;
UdpSocketInAddr.sin_addr.s_addr = INADDR_ANY; UdpSocketInAddr.sin_addr.s_addr = INADDR_ANY;
@ -67,8 +67,8 @@ void CSocket::Init ( const quint16 iPortNumber )
UdpSocketInAddr.sin_port = htons ( iPortNumber + iClientPortIncrement ); UdpSocketInAddr.sin_port = htons ( iPortNumber + iClientPortIncrement );
bSuccess = ( bind ( UdpSocket , bSuccess = ( bind ( UdpSocket ,
(SOCKADDR*) &UdpSocketInAddr, (sockaddr*) &UdpSocketInAddr,
sizeof ( SOCKADDR_IN ) ) == 0 ); sizeof ( sockaddr_in ) ) == 0 );
iClientPortIncrement++; iClientPortIncrement++;
} }
@ -169,7 +169,7 @@ void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
// note that the client uses the socket directly for performance reasons // note that the client uses the socket directly for performance reasons
if ( bIsClient ) if ( bIsClient )
{ {
SOCKADDR_IN UdpSocketOutAddr; sockaddr_in UdpSocketOutAddr;
UdpSocketOutAddr.sin_family = AF_INET; UdpSocketOutAddr.sin_family = AF_INET;
UdpSocketOutAddr.sin_port = htons ( HostAddr.iPort ); UdpSocketOutAddr.sin_port = htons ( HostAddr.iPort );
@ -179,8 +179,8 @@ void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
(const char*) &( (CVector<uint8_t>) vecbySendBuf )[0], (const char*) &( (CVector<uint8_t>) vecbySendBuf )[0],
iVecSizeOut, iVecSizeOut,
0, 0,
(SOCKADDR*) &UdpSocketOutAddr, (sockaddr*) &UdpSocketOutAddr,
sizeof ( SOCKADDR_IN ) ); sizeof ( sockaddr_in ) );
} }
else else
{ {
@ -219,14 +219,18 @@ void CSocket::OnDataReceived()
{ {
// read block from network interface and query address of sender // read block from network interface and query address of sender
#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD #ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
SOCKADDR_IN SenderAddr; sockaddr_in SenderAddr;
int SenderAddrSize = sizeof ( SOCKADDR_IN ); #ifdef _WIN32
int SenderAddrSize = sizeof ( sockaddr_in );
#else
socklen_t SenderAddrSize = sizeof ( sockaddr_in );
#endif
const long iNumBytesRead = recvfrom ( UdpSocket, const long iNumBytesRead = recvfrom ( UdpSocket,
(char*) &vecbyRecBuf[0], (char*) &vecbyRecBuf[0],
MAX_SIZE_BYTES_NETW_BUF, MAX_SIZE_BYTES_NETW_BUF,
0, 0,
(SOCKADDR*) &SenderAddr, (sockaddr*) &SenderAddr,
&SenderAddrSize ); &SenderAddrSize );
#else #else
const int iNumBytesRead = const int iNumBytesRead =

View file

@ -35,6 +35,12 @@
#include "global.h" #include "global.h"
#include "protocol.h" #include "protocol.h"
#include "util.h" #include "util.h"
#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
# ifndef _WIN32
# include <netinet/in.h>
# include <sys/socket.h>
# endif
#endif
// The header files channel.h and server.h require to include this header file // The header files channel.h and server.h require to include this header file
// so we get a cyclic dependency. To solve this issue, a prototype of the // so we get a cyclic dependency. To solve this issue, a prototype of the