1
0
Fork 0

MSVC 7.1 project files - Tile server

This commit is contained in:
Frederic Bouvier 2009-01-18 19:28:14 +01:00 committed by Ralf Gerlich
parent c91ffa08c4
commit 91e1f82e54
4 changed files with 261 additions and 40 deletions

View file

@ -0,0 +1,2 @@
Debug
Release

View file

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="fgfs-launch-server"
ProjectGUID="{5086D5EB-5EC0-437F-8181-264315F21A17}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\..\SimGear.cs;..\..\..\..;..\..\..\..\3rdParty\include;..\..\..\..\install\msvc71\OpenSceneGraph\include;..\..\..\src\Lib;..\..\..\src\BuildTiles;..\..\..\..\gpc232"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;NOMINMAX"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ul_d.lib sg_d.lib zlibd.lib ws2_32.lib"
OutputFile="$(OutDir)/fgfs-launch-server.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\..\plib;..\..\..\..\3rdParty\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/fgfs-launch-server.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\..\SimGear.cs;..\..\..\..;..\..\..\..\3rdParty\include;..\..\..\..\install\msvc71\OpenSceneGraph\include;..\..\..\src\Lib;..\..\..\src\BuildTiles;..\..\..\..\gpc232"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;NOMINMAX"
RuntimeLibrary="2"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ul.lib sg.lib zlib.lib"
OutputFile="$(OutDir)/fgfs-launch-server.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\..\plib;..\..\..\..\3rdParty\lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath="..\..\..\src\BuildTiles\Parallel\server.cxx">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -197,6 +197,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fgfs-construct", "fgfs-cons
{78922FED-3B8B-4276-ADFF-9A19330F7CFE} = {78922FED-3B8B-4276-ADFF-9A19330F7CFE}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fgfs-launch-server", "fgfs-launch-server\fgfs-launch-server.vcproj", "{5086D5EB-5EC0-437F-8181-264315F21A17}"
ProjectSection(ProjectDependencies) = postProject
{22540CD3-D3CA-4C86-A773-80AEEE3ACDED} = {22540CD3-D3CA-4C86-A773-80AEEE3ACDED}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@ -343,6 +348,10 @@ Global
{8AB3DC28-1CAC-4DC0-B8CD-EB066E3711F9}.Debug.Build.0 = Debug|Win32
{8AB3DC28-1CAC-4DC0-B8CD-EB066E3711F9}.Release.ActiveCfg = Release|Win32
{8AB3DC28-1CAC-4DC0-B8CD-EB066E3711F9}.Release.Build.0 = Release|Win32
{5086D5EB-5EC0-437F-8181-264315F21A17}.Debug.ActiveCfg = Debug|Win32
{5086D5EB-5EC0-437F-8181-264315F21A17}.Debug.Build.0 = Debug|Win32
{5086D5EB-5EC0-437F-8181-264315F21A17}.Release.ActiveCfg = Release|Win32
{5086D5EB-5EC0-437F-8181-264315F21A17}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

View file

@ -12,18 +12,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h> // FD_ISSET(), etc.
#ifdef _MSC_VER
# include <winsock2.h>
typedef int socklen_t;
#else
# include <sys/time.h> // FD_ISSET(), etc.
# include <unistd.h>
# include <sys/socket.h> // bind
# include <netinet/in.h>
# include <sys/wait.h>
#endif
#include <sys/stat.h> // for stat()
#include <time.h> // for time();
#include <unistd.h>
#include <sys/socket.h> // bind
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/misc/sg_path.hxx>
using std:: cout ;
using std:: cerr ;
@ -48,6 +54,16 @@ static int pass = 0;
static double area_width = 10.0; // width of generated area in degrees
static double area_height = 10.0; // height of generated area in degrees
#ifdef _MSC_VER
#define numWorkerThreads 10
HANDLE gWorkerThreads[numWorkerThreads];
HANDLE gIoPort;
DWORD WINAPI ThreadProc(void *);
#endif
int make_socket (unsigned short int* port) {
int sock;
@ -297,6 +313,73 @@ void usage( const string name ) {
exit(-1);
}
void alloc_new_tile( int msgsock, long int next_tile, const string &status_dir ) {
// cout << "new process started to handle new connection for "
// << next_tile << endl;
// Read client's message (which is the status of the
// last scenery creation task.)
char buf[MAXBUF];
int length;
if ( (length = recv(msgsock, buf, MAXBUF, 0)) < 0) {
perror("Cannot read command");
exit(-1);
}
buf[length] = '\0';
long int returned_tile = atoi(buf);
cout << "client returned = " << returned_tile << endl;
// record status
if ( returned_tile < 0 ) {
// failure
log_failed_tile( status_dir, -returned_tile );
log_finished_tile( status_dir, -returned_tile );
} else {
// success
log_finished_tile( status_dir, returned_tile );
}
// reply to the client
char message[MAXBUF];
sprintf(message, "%ld", next_tile);
length = strlen(message);
if ( send(msgsock, message, length, 0) < 0 ) {
perror("Cannot write to stream socket");
}
closesocket(msgsock);
// cout << "process for " << next_tile << " ended" << endl;
}
#ifdef _MSC_VER
struct Parameters {
int msgsock;
long next_tile;
string status_dir;
};
DWORD WINAPI
ThreadProc(void* p)
{
unsigned long pN1, pN2;
OVERLAPPED* pOverLapped;
while( GetQueuedCompletionStatus(gIoPort, &pN1, &pN2, &pOverLapped, INFINITE)) {
if (pOverLapped == (OVERLAPPED*)0xFFFFFFFF)
break;
Parameters *p = (Parameters*)pN1;
if ( p ) {
alloc_new_tile( p->msgsock, p->next_tile, p->status_dir );
delete p;
}
}
return 1;
}
#endif
int main( int argc, char **argv ) {
int arg_counter;
@ -305,6 +388,14 @@ int main( int argc, char **argv ) {
fd_set ready;
short unsigned int port;
#ifdef _MSC_VER
gIoPort = CreateIoCompletionPort((HANDLE)INVALID_HANDLE_VALUE, NULL, 0, 0);
for (int n = 0; n < numWorkerThreads; ++n) {
DWORD id;
gWorkerThreads[n] = CreateThread(NULL, 0, ThreadProc, gIoPort, 0, &id);
}
#endif
// Get any options first
int arg_offset = 0;
for (int i = 1; i < argc; i++) {
@ -350,8 +441,9 @@ int main( int argc, char **argv ) {
// create the status directory
string status_dir = work_base + "/Status";
string command = "mkdir -p " + status_dir;
system( command.c_str() );
SGPath sgp( status_dir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
// setup socket to listen on
sock = make_socket( &port );
@ -391,6 +483,7 @@ int main( int argc, char **argv ) {
msgsock = accept(sock, 0, 0);
// cout << "msgsock = " << msgsock << endl;
#ifndef _MSC_VER
// spawn a child
pid = fork();
@ -412,42 +505,19 @@ int main( int argc, char **argv ) {
// This is the child
close(sock);
// cout << "new process started to handle new connection for "
// << next_tile << endl;
// Read client's message (which is the status of the
// last scenery creation task.)
char buf[MAXBUF];
if ( (length = read(msgsock, buf, MAXBUF)) < 0) {
perror("Cannot read command");
exit(-1);
}
buf[length] = '\0';
long int returned_tile = atoi(buf);
cout << "client returned = " << returned_tile << endl;
// record status
if ( returned_tile < 0 ) {
// failure
log_failed_tile( status_dir, -returned_tile );
log_finished_tile( status_dir, -returned_tile );
} else {
// success
log_finished_tile( status_dir, returned_tile );
}
// reply to the client
char message[MAXBUF];
sprintf(message, "%ld", next_tile);
length = strlen(message);
if ( write(msgsock, message, length) < 0 ) {
perror("Cannot write to stream socket");
}
close(msgsock);
// cout << "process for " << next_tile << " ended" << endl;
alloc_new_tile( msgsock, next_tile, status_dir );
exit(0);
}
#else
Parameters *p = new Parameters;
p->msgsock = msgsock;
p->next_tile = next_tile;
p->status_dir = status_dir;
PostQueuedCompletionStatus(gIoPort, (DWORD)p, 0, NULL);
#endif
}
}
}