mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 03:04:33 +02:00
Merge pull request #20 from dominiquevincent/19197
Code Review for Job #19197
This commit is contained in:
commit
84456ac9af
23 changed files with 3110 additions and 41 deletions
|
@ -18,8 +18,7 @@ endif (APPLE)
|
|||
|
||||
if (WIN32)
|
||||
set(GLUT_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/glut)
|
||||
set(GL_HEADERS "#define GLEW_STATIC\n#define FREEGLUT_STATIC\n#define FREEGLUT_LIB_PRAGMAS 0
|
||||
#include <GL/glew.h>\n#include <GL/freeglut_std.h>\n#include <GL/freeglut_ext.h>")
|
||||
set(GL_HEADERS "#define GLEW_STATIC\n#define FREEGLUT_STATIC\n#define FREEGLUT_LIB_PRAGMAS 0\n#include <GL/glew.h>\n#include <GL/wglew.h>\n#include <GL/freeglut_std.h>\n#include <GL/freeglut_ext.h>")
|
||||
endif (WIN32)
|
||||
|
||||
# create the InterfaceConfig.h file based on GL_HEADERS above
|
||||
|
|
1363
interface/external/glut/include/GL/wglew.h
vendored
Normal file
1363
interface/external/glut/include/GL/wglew.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -34,7 +34,7 @@ float browThickness = 0.16;
|
|||
|
||||
const float DECAY = 0.1;
|
||||
|
||||
char iris_texture_file[] = "images/green_eye.png";
|
||||
char iris_texture_file[] = "resources/images/green_eye.png";
|
||||
|
||||
vector<unsigned char> iris_texture;
|
||||
unsigned int iris_texture_width = 512;
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
*/
|
||||
bool addShader(GLenum type, GLchar const* cString) {
|
||||
|
||||
addShader(type, 1, & cString);
|
||||
return addShader(type, 1, & cString);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
// Created by Philip on 12/31/12.
|
||||
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _timeval_
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <iostream> // to load voxels from file
|
||||
|
@ -13,6 +16,7 @@
|
|||
#include <SharedUtil.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include <OctalCode.h>
|
||||
#include <pthread.h>
|
||||
#include "VoxelSystem.h"
|
||||
|
||||
const int MAX_VOXELS_PER_SYSTEM = 250000;
|
||||
|
|
|
@ -815,8 +815,7 @@ void display(void)
|
|||
glVertex2f(headMouseX + PIXEL_BOX/2, headMouseY + PIXEL_BOX/2);
|
||||
glVertex2f(headMouseX - PIXEL_BOX/2, headMouseY + PIXEL_BOX/2);
|
||||
glVertex2f(headMouseX - PIXEL_BOX/2, headMouseY - PIXEL_BOX/2);
|
||||
glEnd();
|
||||
|
||||
glEnd();
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
|
@ -831,6 +830,7 @@ void display(void)
|
|||
}
|
||||
|
||||
// Draw number of nearby people always
|
||||
glPointSize(1.0f);
|
||||
char agents[100];
|
||||
sprintf(agents, "Agents nearby: %ld\n", agentList.getAgents().size());
|
||||
drawtext(WIDTH-200,20, 0.10, 0, 1.0, 0, agents, 1, 1, 0);
|
||||
|
@ -969,8 +969,9 @@ void specialkey(int k, int x, int y)
|
|||
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(RIGHT, 1);
|
||||
else myHead.setDriveKeys(ROT_RIGHT, 1);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
audio.setWalkingState(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1234,16 +1235,16 @@ int main(int argc, const char * argv[])
|
|||
#ifndef _WIN32
|
||||
agentList.audioMixerSocketUpdate = &audioMixerUpdate;
|
||||
#endif
|
||||
|
||||
// start the thread which checks for silent agents
|
||||
agentList.startSilentAgentRemovalThread();
|
||||
agentList.startDomainServerCheckInThread();
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA WsaData;
|
||||
int wsaresult = WSAStartup( MAKEWORD(2,2), &WsaData );
|
||||
#endif
|
||||
|
||||
// start the thread which checks for silent agents
|
||||
agentList.startSilentAgentRemovalThread();
|
||||
agentList.startDomainServerCheckInThread();
|
||||
|
||||
glutInit(&argc, (char**)argv);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(WIDTH, HEIGHT);
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace starfield {
|
|||
// ww + ww aa = dd
|
||||
// ww = dd / (1 + aa)
|
||||
float diag = 2.0f * std::sin(halfPersp);
|
||||
float near = std::cos(halfPersp);
|
||||
float nearClip = std::cos(halfPersp);
|
||||
|
||||
float hw = 0.5f * sqrt(diag * diag / (1.0f + aspect * aspect));
|
||||
float hh = hw * aspect;
|
||||
|
@ -165,11 +165,11 @@ namespace starfield {
|
|||
|
||||
#if STARFIELD_DEBUG_LOD
|
||||
mat4 matrix_debug = glm::translate(
|
||||
glm::frustum(-hw,hw, -hh,hh, near,10.0f),
|
||||
glm::frustum(-hw, hw, -hh, hh, nearClip, 10.0f),
|
||||
vec3(0.0f, 0.0f, -4.0f)) * glm::affineInverse(matrix);
|
||||
#endif
|
||||
|
||||
matrix = glm::frustum(-hw,hw, -hh,hh, near,10.0f)
|
||||
matrix = glm::frustum(-hw,hw, -hh,hh, nearClip,10.0f)
|
||||
* glm::affineInverse(matrix);
|
||||
|
||||
this->_itrOutIndex = (unsigned*) _arrBatchOffs;
|
||||
|
@ -374,11 +374,11 @@ namespace starfield {
|
|||
float halfSlice = 0.5f * slice;
|
||||
float daz = halfSlice * cos(abs(altitude) - halfSlice);
|
||||
float dal = halfSlice;
|
||||
float near = cos(_valHalfPersp + sqrt(daz*daz+dal*dal));
|
||||
float adjustedNear = cos(_valHalfPersp + sqrt(daz * daz + dal * dal));
|
||||
|
||||
// fprintf(stderr, "Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, near);
|
||||
// fprintf(stderr, "Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip);
|
||||
|
||||
return w > near;
|
||||
return w > adjustedNear;
|
||||
}
|
||||
|
||||
void updateVertexCount(Tile* t, BrightnessLevel minBright) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// starfield/renderer/Tiling.h
|
||||
// starfield/renderer/
|
||||
// interface
|
||||
//
|
||||
// Created by Tobias Schwinger on 3/22/13.
|
||||
|
@ -13,8 +13,15 @@
|
|||
#error "This is an implementation file - not intended for direct inclusion."
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../Config.h"
|
||||
#define lrint(x) (floor(x + (x > 0) ? 0.5 : -0.5))
|
||||
inline float remainder(float x, float y) { return std::fmod(x, y); }
|
||||
inline int round(float x) { return (floor(x + 0.5)); }
|
||||
double log2( double n ) { return log( n ) / log( 2 ); }
|
||||
#else
|
||||
#include "starfield/Config.h"
|
||||
|
||||
#endif
|
||||
namespace starfield {
|
||||
|
||||
class Tiling {
|
||||
|
|
|
@ -9,10 +9,19 @@ file(GLOB HIFI_SHARED_SRCS src/*.h src/*.cpp)
|
|||
add_library(HifiShared ${HIFI_SHARED_SRCS})
|
||||
set(HIFI_SHARED_LIBRARY HifiShared)
|
||||
|
||||
find_package(CURL REQUIRED)
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
# link target to common, external libraries
|
||||
target_link_libraries(HifiShared ${CURL_LIBRARY})
|
||||
set(EXTERNAL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
|
||||
if (WIN32)
|
||||
# include headers for external libraries and InterfaceConfig.
|
||||
include_directories(${EXTERNAL_ROOT_DIR})
|
||||
endif (WIN32)
|
||||
|
||||
if (NOT WIN32)
|
||||
find_package(CURL REQUIRED)
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
# link target to common, external libraries
|
||||
target_link_libraries(HifiShared ${CURL_LIBRARY})
|
||||
endif (NOT WIN32)
|
||||
|
||||
# link required libraries on UNIX
|
||||
if (UNIX AND NOT APPLE)
|
||||
|
|
1403
shared/external/pthread.h
vendored
Normal file
1403
shared/external/pthread.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
189
shared/external/sched.h
vendored
Normal file
189
shared/external/sched.h
vendored
Normal file
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Module: sched.h
|
||||
*
|
||||
* Purpose:
|
||||
* Provides an implementation of POSIX realtime extensions
|
||||
* as defined in
|
||||
*
|
||||
* POSIX 1003.1b-1993 (POSIX.1b)
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Pthreads-win32 - POSIX Threads Library for Win32
|
||||
* Copyright(C) 1998 John E. Bossom
|
||||
* Copyright(C) 1999,2005 Pthreads-win32 contributors
|
||||
*
|
||||
* Contact Email: rpj@callisto.canberra.edu.au
|
||||
*
|
||||
* The current list of contributors is contained
|
||||
* in the file CONTRIBUTORS included with the source
|
||||
* code distribution. The list can also be seen at the
|
||||
* following World Wide Web location:
|
||||
* http://sources.redhat.com/pthreads-win32/contributors.html
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library in the file COPYING.LIB;
|
||||
* if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(_SCHED_H)
|
||||
#define _SCHED_H
|
||||
|
||||
#undef PTW32_SCHED_LEVEL
|
||||
|
||||
#if defined(_POSIX_SOURCE)
|
||||
#define PTW32_SCHED_LEVEL 0
|
||||
/* Early POSIX */
|
||||
#endif
|
||||
|
||||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
|
||||
#undef PTW32_SCHED_LEVEL
|
||||
#define PTW32_SCHED_LEVEL 1
|
||||
/* Include 1b, 1c and 1d */
|
||||
#endif
|
||||
|
||||
#if defined(INCLUDE_NP)
|
||||
#undef PTW32_SCHED_LEVEL
|
||||
#define PTW32_SCHED_LEVEL 2
|
||||
/* Include Non-Portable extensions */
|
||||
#endif
|
||||
|
||||
#define PTW32_SCHED_LEVEL_MAX 3
|
||||
|
||||
#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL)
|
||||
#define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX
|
||||
/* Include everything */
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__GNUC__) && !defined(__declspec)
|
||||
# error Please upgrade your GNU compiler to one that supports __declspec.
|
||||
#endif
|
||||
|
||||
/*
|
||||
* When building the library, you should define PTW32_BUILD so that
|
||||
* the variables/functions are exported correctly. When using the library,
|
||||
* do NOT define PTW32_BUILD, and then the variables/functions will
|
||||
* be imported correctly.
|
||||
*/
|
||||
#if !defined(PTW32_STATIC_LIB)
|
||||
# if defined(PTW32_BUILD)
|
||||
# define PTW32_DLLPORT __declspec (dllexport)
|
||||
# else
|
||||
# define PTW32_DLLPORT __declspec (dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define PTW32_DLLPORT
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is a duplicate of what is in the autoconf config.h,
|
||||
* which is only used when building the pthread-win32 libraries.
|
||||
*/
|
||||
|
||||
#if !defined(PTW32_CONFIG_H)
|
||||
# if defined(WINCE)
|
||||
# define NEED_ERRNO
|
||||
# define NEED_SEM
|
||||
# endif
|
||||
# if defined(__MINGW64__)
|
||||
# define HAVE_STRUCT_TIMESPEC
|
||||
# define HAVE_MODE_T
|
||||
# elif defined(_UWIN) || defined(__MINGW32__)
|
||||
# define HAVE_MODE_T
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX
|
||||
#if defined(NEED_ERRNO)
|
||||
#include "need_errno.h"
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */
|
||||
|
||||
#if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN)
|
||||
# if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX
|
||||
/* For pid_t */
|
||||
# include <sys/types.h>
|
||||
/* Required by Unix 98 */
|
||||
# include <time.h>
|
||||
# else
|
||||
typedef int pid_t;
|
||||
# endif
|
||||
#else
|
||||
/* [i_a] fix for using pthread_win32 with mongoose code, which #define's its own pid_t akin to typedef HANDLE pid_t; */
|
||||
#undef pid_t
|
||||
# if defined(_MSC_VER)
|
||||
typedef void *pid_t;
|
||||
# else
|
||||
typedef int pid_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Thread scheduling policies */
|
||||
|
||||
enum {
|
||||
SCHED_OTHER = 0,
|
||||
SCHED_FIFO,
|
||||
SCHED_RR,
|
||||
SCHED_MIN = SCHED_OTHER,
|
||||
SCHED_MAX = SCHED_RR
|
||||
};
|
||||
|
||||
struct sched_param {
|
||||
int sched_priority;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
PTW32_DLLPORT int __cdecl sched_yield (void);
|
||||
|
||||
PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);
|
||||
|
||||
PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);
|
||||
|
||||
PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);
|
||||
|
||||
PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);
|
||||
|
||||
/*
|
||||
* Note that this macro returns ENOTSUP rather than
|
||||
* ENOSYS as might be expected. However, returning ENOSYS
|
||||
* should mean that sched_get_priority_{min,max} are
|
||||
* not implemented as well as sched_rr_get_interval.
|
||||
* This is not the case, since we just don't support
|
||||
* round-robin scheduling. Therefore I have chosen to
|
||||
* return the same value as sched_setscheduler when
|
||||
* SCHED_RR is passed to it.
|
||||
*/
|
||||
#define sched_rr_get_interval(_pid, _interval) \
|
||||
( errno = ENOTSUP, (int) -1 )
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* End of extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#undef PTW32_SCHED_LEVEL
|
||||
#undef PTW32_SCHED_LEVEL_MAX
|
||||
|
||||
#endif /* !_SCHED_H */
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <pthread.h>
|
||||
#include "Agent.h"
|
||||
#include "AgentTypes.h"
|
||||
#include <cstring>
|
||||
|
|
|
@ -311,6 +311,18 @@ void AgentList::stopSilentAgentRemovalThread() {
|
|||
pthread_join(removeSilentAgentsThread, NULL);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void usleep(int waitTime) {
|
||||
__int64 time1 = 0, time2 = 0, sysFreq = 0;
|
||||
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&time1);
|
||||
QueryPerformanceFrequency((LARGE_INTEGER *)&sysFreq);
|
||||
do {
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&time2);
|
||||
} while( (time2 - time1) < waitTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
void *checkInWithDomainServer(void *args) {
|
||||
|
||||
AgentList *parentAgentList = (AgentList *)args;
|
||||
|
|
|
@ -11,7 +11,12 @@
|
|||
|
||||
#include "CounterStats.h"
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "PerfStat.h"
|
||||
#include <cstdio>
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
|
|
@ -12,6 +12,15 @@
|
|||
#ifndef __hifi__PerfStat__
|
||||
#define __hifi__PerfStat__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define snprintf _snprintf
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
#ifdef _WIN32
|
||||
#define WINSOCK_API_LINKAGE
|
||||
#include <winsock2.h>
|
||||
#ifndef _timeval_
|
||||
#define _timeval_
|
||||
|
||||
#endif
|
||||
typedef SSIZE_T ssize_t;
|
||||
typedef ULONG32 in_addr_t;
|
||||
typedef USHORT in_port_t;
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
#define _timeval_
|
||||
|
||||
#include "Systime.h"
|
||||
|
||||
int gettimeofday( timeval* p_tv, timezone* p_tz )
|
||||
{
|
||||
int tt = timeGetTime();
|
||||
|
||||
p_tv->tv_sec = tt / 1000;
|
||||
p_tv->tv_sec = tt % 1000 *1000;
|
||||
return 0;
|
||||
}
|
||||
int gettimeofday( timeval* p_tv, timezone* p_tz )
|
||||
{
|
||||
int tt = timeGetTime();
|
||||
|
||||
p_tv->tv_sec = tt / 1000;
|
||||
p_tv->tv_usec = tt % 1000 * 1000;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
#define __Systime__
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef _WINSOCK2API_
|
||||
#define _timeval_
|
||||
#endif
|
||||
#ifndef _timeval_
|
||||
#define _timeval_
|
||||
/*
|
||||
* Structure returned by gettimeofday(2) system call,
|
||||
* and used in other calls.
|
||||
|
|
|
@ -72,8 +72,9 @@ int getLocalAddress() {
|
|||
|
||||
int family;
|
||||
int localAddress = 0;
|
||||
|
||||
getifaddrs(&ifAddrStruct);
|
||||
|
||||
#ifndef _WIN32
|
||||
getifaddrs(&ifAddrStruct);
|
||||
|
||||
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
family = ifa->ifa_addr->sa_family;
|
||||
|
@ -83,11 +84,22 @@ int getLocalAddress() {
|
|||
}
|
||||
|
||||
freeifaddrs(ifAddrStruct);
|
||||
#else
|
||||
// Get the local hostname
|
||||
char szHostName[255];
|
||||
gethostname(szHostName, 255);
|
||||
struct hostent *host_entry;
|
||||
host_entry = gethostbyname(szHostName);
|
||||
char * szLocalIP;
|
||||
szLocalIP = inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list);
|
||||
localAddress = inet_addr(szLocalIP);
|
||||
#endif
|
||||
|
||||
return localAddress;
|
||||
}
|
||||
|
||||
UDPSocket::UDPSocket(int listeningPort) {
|
||||
init();
|
||||
// create the socket
|
||||
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
|
@ -126,6 +138,38 @@ UDPSocket::~UDPSocket() {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool UDPSocket::init() {
|
||||
#ifdef _WIN32
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
int err;
|
||||
|
||||
wVersionRequested = MAKEWORD( 2, 2 );
|
||||
|
||||
err = WSAStartup( wVersionRequested, &wsaData );
|
||||
if ( err != 0 ) {
|
||||
/* Tell the user that we could not find a usable */
|
||||
/* WinSock DLL. */
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Confirm that the WinSock DLL supports 2.2.*/
|
||||
/* Note that if the DLL supports versions later */
|
||||
/* than 2.2 in addition to 2.2, it will still return */
|
||||
/* 2.2 in wVersion since that is the version we */
|
||||
/* requested. */
|
||||
|
||||
if ( LOBYTE( wsaData.wVersion ) != 2 ||
|
||||
HIBYTE( wsaData.wVersion ) != 2 ) {
|
||||
/* Tell the user that we could not find a usable */
|
||||
/* WinSock DLL. */
|
||||
WSACleanup();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// Receive data on this socket with retrieving address of sender
|
||||
bool UDPSocket::receive(void *receivedData, ssize_t *receivedBytes) {
|
||||
|
||||
|
@ -135,8 +179,11 @@ bool UDPSocket::receive(void *receivedData, ssize_t *receivedBytes) {
|
|||
// Receive data on this socket with the address of the sender
|
||||
bool UDPSocket::receive(sockaddr *recvAddress, void *receivedData, ssize_t *receivedBytes) {
|
||||
|
||||
#ifdef _WIN32
|
||||
int addressSize = sizeof(*recvAddress);
|
||||
#else
|
||||
socklen_t addressSize = sizeof(&recvAddress);
|
||||
|
||||
#endif
|
||||
*receivedBytes = recvfrom(handle, static_cast<char*>(receivedData), MAX_BUFFER_LENGTH_BYTES,
|
||||
0, recvAddress, &addressSize);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ class UDPSocket {
|
|||
public:
|
||||
UDPSocket(int listening_port);
|
||||
~UDPSocket();
|
||||
bool init();
|
||||
int send(sockaddr *destAddress, const void *data, size_t byteLength);
|
||||
int send(char *destAddress, int destPort, const void *data, size_t byteLength);
|
||||
bool receive(void *receivedData, ssize_t *receivedBytes);
|
||||
|
|
|
@ -10,9 +10,15 @@
|
|||
#include "UrlReader.h"
|
||||
|
||||
#include <new>
|
||||
#ifdef _WIN32
|
||||
#define NOCURL_IN_WINDOWS
|
||||
#endif
|
||||
#ifndef NOCURL_IN_WINDOWS
|
||||
#include <curl/curl.h>
|
||||
|
||||
size_t const UrlReader::max_read_ahead = CURL_MAX_WRITE_SIZE;
|
||||
#else
|
||||
size_t const UrlReader::max_read_ahead = 0;
|
||||
#endif
|
||||
|
||||
char const* const UrlReader::success = "UrlReader: Success!";
|
||||
char const* const UrlReader::error_init_failed = "UrlReader: Initialization failed.";
|
||||
|
@ -27,21 +33,26 @@ UrlReader::UrlReader()
|
|||
|
||||
_arrXtra = new(std::nothrow) char[max_read_ahead];
|
||||
if (! _arrXtra) { _strError = error_init_failed; return; }
|
||||
#ifndef NOCURL_IN_WINDOWS
|
||||
_ptrImpl = curl_easy_init();
|
||||
if (! _ptrImpl) { _strError = error_init_failed; return; }
|
||||
curl_easy_setopt(hnd_curl, CURLOPT_NOSIGNAL, 1l);
|
||||
curl_easy_setopt(hnd_curl, CURLOPT_FAILONERROR, 1l);
|
||||
curl_easy_setopt(hnd_curl, CURLOPT_FILETIME, 1l);
|
||||
#endif
|
||||
}
|
||||
|
||||
UrlReader::~UrlReader() {
|
||||
|
||||
delete _arrXtra;
|
||||
#ifndef NOCURL_IN_WINDOWS
|
||||
if (! hnd_curl) return;
|
||||
curl_easy_cleanup(hnd_curl);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool UrlReader::perform(char const* url, transfer_callback* cb) {
|
||||
#ifndef NOCURL_IN_WINDOWS
|
||||
|
||||
curl_easy_setopt(hnd_curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(hnd_curl, CURLOPT_WRITEFUNCTION, cb);
|
||||
|
@ -58,10 +69,14 @@ bool UrlReader::perform(char const* url, transfer_callback* cb) {
|
|||
_strError = curl_easy_strerror(rc);
|
||||
|
||||
return rc == CURLE_OK;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UrlReader::getinfo(char const*& url,
|
||||
char const*& type, int64_t& length, int64_t& stardate) {
|
||||
#ifndef NOCURL_IN_WINDOWS
|
||||
|
||||
curl_easy_getinfo(hnd_curl, CURLINFO_EFFECTIVE_URL, & url);
|
||||
curl_easy_getinfo(hnd_curl, CURLINFO_CONTENT_TYPE, & type);
|
||||
|
@ -73,5 +88,6 @@ void UrlReader::getinfo(char const*& url,
|
|||
long time;
|
||||
curl_easy_getinfo(hnd_curl, CURLINFO_FILETIME, & time);
|
||||
stardate = time;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
|
Loading…
Reference in a new issue