2008-02-01 08:50:56 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// File: svutil.cpp
|
|
|
|
// Description: ScrollView Utilities
|
|
|
|
// Author: Joern Wanke
|
|
|
|
// Created: Thu Nov 29 2007
|
|
|
|
//
|
|
|
|
// (C) Copyright 2007, Google Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SVUtil contains the SVSync and SVNetwork classes, which are used for
|
|
|
|
// thread/process creation & synchronization and network connection.
|
|
|
|
|
2010-05-20 05:19:00 +08:00
|
|
|
#include <stdio.h>
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2010-05-20 05:19:00 +08:00
|
|
|
struct addrinfo {
|
|
|
|
struct sockaddr* ai_addr;
|
|
|
|
int ai_addrlen;
|
|
|
|
int ai_family;
|
|
|
|
int ai_socktype;
|
|
|
|
int ai_protocol;
|
|
|
|
};
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
2008-12-31 02:38:30 +08:00
|
|
|
#include <arpa/inet.h>
|
2009-03-13 07:52:44 +08:00
|
|
|
#include <netinet/in.h>
|
2008-02-01 08:50:56 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <signal.h>
|
2009-06-03 07:34:41 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-02-01 08:50:56 +08:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
2008-04-22 08:44:56 +08:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
2012-02-02 11:14:43 +08:00
|
|
|
#include <unistd.h>
|
2008-02-01 08:50:56 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-21 07:38:12 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2008-02-01 08:50:56 +08:00
|
|
|
#include <iostream>
|
2010-05-20 05:19:00 +08:00
|
|
|
#include <string>
|
2008-02-01 08:50:56 +08:00
|
|
|
|
2010-09-30 23:53:40 +08:00
|
|
|
// Include automatically generated configuration file if running autoconf.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config_auto.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GRAPHICS_DISABLED
|
|
|
|
|
|
|
|
#include "svutil.h"
|
|
|
|
|
2008-02-01 08:50:56 +08:00
|
|
|
const int kBufferSize = 65536;
|
|
|
|
const int kMaxMsgSize = 4096;
|
|
|
|
|
|
|
|
// Signals a thread to exit.
|
|
|
|
void SVSync::ExitThread() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2011-08-16 03:28:25 +08:00
|
|
|
// ExitThread(0);
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
|
|
|
pthread_exit(0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Starts a new process.
|
|
|
|
void SVSync::StartProcess(const char* executable, const char* args) {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
std::string proc;
|
|
|
|
proc.append(executable);
|
|
|
|
proc.append(" ");
|
|
|
|
proc.append(args);
|
|
|
|
std::cout << "Starting " << proc << std::endl;
|
2008-08-15 06:52:14 +08:00
|
|
|
STARTUPINFO start_info;
|
|
|
|
PROCESS_INFORMATION proc_info;
|
|
|
|
GetStartupInfo(&start_info);
|
|
|
|
if (!CreateProcess(NULL, const_cast<char*>(proc.c_str()), NULL, NULL, FALSE,
|
|
|
|
CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL,
|
|
|
|
&start_info, &proc_info))
|
|
|
|
return;
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
|
|
|
int pid = fork();
|
|
|
|
if (pid != 0) { // The father process returns
|
|
|
|
} else {
|
2008-04-22 08:44:56 +08:00
|
|
|
#ifdef __linux__
|
|
|
|
// Make sure the java process terminates on exit, since its
|
|
|
|
// broken socket detection seems to be useless.
|
|
|
|
prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
|
|
|
|
#endif
|
2008-02-01 08:50:56 +08:00
|
|
|
char* mutable_args = strdup(args);
|
|
|
|
int argc = 1;
|
|
|
|
for (int i = 0; mutable_args[i]; ++i) {
|
|
|
|
if (mutable_args[i] == ' ') {
|
|
|
|
++argc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char** argv = new char*[argc + 2];
|
|
|
|
argv[0] = strdup(executable);
|
|
|
|
argv[1] = mutable_args;
|
|
|
|
argc = 2;
|
|
|
|
bool inquote = false;
|
|
|
|
for (int i = 0; mutable_args[i]; ++i) {
|
|
|
|
if (!inquote && mutable_args[i] == ' ') {
|
|
|
|
mutable_args[i] = '\0';
|
|
|
|
argv[argc++] = mutable_args + i + 1;
|
|
|
|
} else if (mutable_args[i] == '"') {
|
|
|
|
inquote = !inquote;
|
|
|
|
mutable_args[i] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argv[argc] = NULL;
|
|
|
|
execvp(executable, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SVSemaphore::SVSemaphore() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
semaphore_ = CreateSemaphore(0, 0, 10, 0);
|
2013-09-23 23:26:50 +08:00
|
|
|
#elif defined(__APPLE__)
|
2013-02-23 19:57:40 +08:00
|
|
|
char name[50];
|
2013-09-23 23:26:50 +08:00
|
|
|
snprintf(name, sizeof(name), "%d", random());
|
2013-02-23 19:57:40 +08:00
|
|
|
sem_unlink(name);
|
|
|
|
semaphore_ = sem_open(name, O_CREAT , S_IWUSR, 0);
|
|
|
|
if (semaphore_ == SEM_FAILED) {
|
2013-09-23 23:26:50 +08:00
|
|
|
perror("sem_open");
|
|
|
|
}
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
|
|
|
sem_init(&semaphore_, 0, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVSemaphore::Signal() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
ReleaseSemaphore(semaphore_, 1, NULL);
|
2013-09-23 23:26:50 +08:00
|
|
|
#elif defined(__APPLE__)
|
2013-02-23 19:57:40 +08:00
|
|
|
sem_post(semaphore_);
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
|
|
|
sem_post(&semaphore_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVSemaphore::Wait() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
WaitForSingleObject(semaphore_, INFINITE);
|
2013-09-23 23:26:50 +08:00
|
|
|
#elif defined(__APPLE__)
|
2013-02-23 19:57:40 +08:00
|
|
|
sem_wait(semaphore_);
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
|
|
|
sem_wait(&semaphore_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SVMutex::SVMutex() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
mutex_ = CreateMutex(0, FALSE, 0);
|
|
|
|
#else
|
|
|
|
pthread_mutex_init(&mutex_, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVMutex::Lock() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
WaitForSingleObject(mutex_, INFINITE);
|
|
|
|
#else
|
|
|
|
pthread_mutex_lock(&mutex_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVMutex::Unlock() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
ReleaseMutex(mutex_);
|
|
|
|
#else
|
|
|
|
pthread_mutex_unlock(&mutex_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new thread.
|
|
|
|
|
2008-04-22 08:44:56 +08:00
|
|
|
void SVSync::StartThread(void *(*func)(void*), void* arg) {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE) func;
|
|
|
|
DWORD threadid;
|
|
|
|
HANDLE newthread = CreateThread(
|
|
|
|
NULL, // default security attributes
|
|
|
|
0, // use default stack size
|
|
|
|
f, // thread function
|
|
|
|
arg, // argument to thread function
|
|
|
|
0, // use default creation flags
|
|
|
|
&threadid); // returns the thread identifier
|
|
|
|
#else
|
|
|
|
pthread_t helper;
|
|
|
|
pthread_create(&helper, NULL, func, arg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place a message in the message buffer (and flush it).
|
|
|
|
void SVNetwork::Send(const char* msg) {
|
|
|
|
mutex_send_->Lock();
|
|
|
|
msg_buffer_out_.append(msg);
|
|
|
|
mutex_send_->Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the whole buffer.
|
|
|
|
void SVNetwork::Flush() {
|
|
|
|
mutex_send_->Lock();
|
|
|
|
while (msg_buffer_out_.size() > 0) {
|
|
|
|
int i = send(stream_, msg_buffer_out_.c_str(), msg_buffer_out_.length(), 0);
|
|
|
|
msg_buffer_out_.erase(0, i);
|
|
|
|
}
|
|
|
|
mutex_send_->Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Receive a message from the server.
|
|
|
|
// This will always return one line of char* (denoted by \n).
|
|
|
|
char* SVNetwork::Receive() {
|
|
|
|
char* result = NULL;
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
if (has_content) { result = strtok (NULL, "\n"); }
|
|
|
|
#else
|
|
|
|
if (buffer_ptr_ != NULL) { result = strtok_r(NULL, "\n", &buffer_ptr_); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// This means there is something left in the buffer and we return it.
|
|
|
|
if (result != NULL) { return result;
|
|
|
|
// Otherwise, we read from the stream_.
|
|
|
|
} else {
|
|
|
|
buffer_ptr_ = NULL;
|
2008-04-22 08:44:56 +08:00
|
|
|
has_content = false;
|
2008-02-01 08:50:56 +08:00
|
|
|
|
|
|
|
// The timeout length is not really important since we are looping anyway
|
|
|
|
// until a new message is delivered.
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = 10;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
// Set the flags to return when the stream_ is ready to be read.
|
|
|
|
fd_set readfds;
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
FD_SET(stream_, &readfds);
|
|
|
|
|
|
|
|
int i = select(stream_+1, &readfds, NULL, NULL, &tv);
|
|
|
|
|
|
|
|
// The stream_ died.
|
|
|
|
if (i == 0) { return NULL; }
|
|
|
|
|
|
|
|
// Read the message buffer.
|
|
|
|
i = recv(stream_, msg_buffer_in_, kMaxMsgSize, 0);
|
|
|
|
|
|
|
|
// Server quit (0) or error (-1).
|
|
|
|
if (i <= 0) { return NULL; }
|
|
|
|
msg_buffer_in_[i] = '\0';
|
|
|
|
has_content = true;
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2011-08-16 03:28:25 +08:00
|
|
|
return strtok(msg_buffer_in_, "\n");
|
2008-02-01 08:50:56 +08:00
|
|
|
#else
|
|
|
|
// Setup a new string tokenizer.
|
|
|
|
return strtok_r(msg_buffer_in_, "\n", &buffer_ptr_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close the connection to the server.
|
|
|
|
void SVNetwork::Close() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
closesocket(stream_);
|
|
|
|
#else
|
|
|
|
close(stream_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 05:19:00 +08:00
|
|
|
// The program to invoke to start ScrollView
|
|
|
|
static const char* ScrollViewProg() {
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2010-05-20 05:19:00 +08:00
|
|
|
const char* prog = "java -Xms512m -Xmx1024m";
|
|
|
|
#else
|
|
|
|
const char* prog = "sh";
|
|
|
|
#endif
|
|
|
|
return prog;
|
|
|
|
}
|
2008-02-01 08:50:56 +08:00
|
|
|
|
|
|
|
|
2010-05-20 05:19:00 +08:00
|
|
|
// The arguments to the program to invoke to start ScrollView
|
|
|
|
static std::string ScrollViewCommand(std::string scrollview_path) {
|
|
|
|
// The following ugly ifdef is to enable the output of the java runtime
|
|
|
|
// to be sent down a black hole on non-windows to ignore all the
|
|
|
|
// exceptions in piccolo. Ideally piccolo would be debugged to make
|
|
|
|
// this unnecessary.
|
|
|
|
// Also the path has to be separated by ; on windows and : otherwise.
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2010-05-20 05:19:00 +08:00
|
|
|
const char* cmd_template = "-Djava.library.path=%s -cp %s/ScrollView.jar;"
|
|
|
|
"%s/piccolo-1.2.jar;%s/piccolox-1.2.jar"
|
|
|
|
" com.google.scrollview.ScrollView";
|
|
|
|
#else
|
2013-02-23 19:57:40 +08:00
|
|
|
const char* cmd_template = "-c \"trap 'kill %%1' 0 1 2 ; java "
|
2010-05-20 05:19:00 +08:00
|
|
|
"-Xms1024m -Xmx2048m -Djava.library.path=%s -cp %s/ScrollView.jar:"
|
|
|
|
"%s/piccolo-1.2.jar:%s/piccolox-1.2.jar"
|
|
|
|
" com.google.scrollview.ScrollView"
|
|
|
|
" >/dev/null 2>&1 & wait\"";
|
|
|
|
#endif
|
|
|
|
int cmdlen = strlen(cmd_template) + 4*strlen(scrollview_path.c_str()) + 1;
|
|
|
|
char* cmd = new char[cmdlen];
|
|
|
|
const char* sv_path = scrollview_path.c_str();
|
|
|
|
snprintf(cmd, cmdlen, cmd_template, sv_path, sv_path, sv_path, sv_path);
|
|
|
|
std::string command(cmd);
|
|
|
|
delete [] cmd;
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Platform-independent freeaddrinfo()
|
|
|
|
static void FreeAddrInfo(struct addrinfo* addr_info) {
|
|
|
|
#if defined(__linux__)
|
|
|
|
freeaddrinfo(addr_info);
|
|
|
|
#else
|
|
|
|
delete addr_info->ai_addr;
|
|
|
|
delete addr_info;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-02-01 08:50:56 +08:00
|
|
|
|
2010-05-20 05:19:00 +08:00
|
|
|
// Non-linux version of getaddrinfo()
|
|
|
|
#if !defined(__linux__)
|
|
|
|
static int GetAddrInfoNonLinux(const char* hostname, int port,
|
|
|
|
struct addrinfo** addr_info) {
|
2008-02-01 08:50:56 +08:00
|
|
|
// Get the host data depending on the OS.
|
2010-05-20 05:19:00 +08:00
|
|
|
struct sockaddr_in* address;
|
|
|
|
*addr_info = new struct addrinfo;
|
|
|
|
memset(*addr_info, 0, sizeof(struct addrinfo));
|
|
|
|
address = new struct sockaddr_in;
|
|
|
|
memset(address, 0, sizeof(struct sockaddr_in));
|
|
|
|
|
|
|
|
(*addr_info)->ai_addr = (struct sockaddr*) address;
|
|
|
|
(*addr_info)->ai_addrlen = sizeof(struct sockaddr);
|
|
|
|
(*addr_info)->ai_family = AF_INET;
|
|
|
|
(*addr_info)->ai_socktype = SOCK_STREAM;
|
|
|
|
|
|
|
|
struct hostent *name;
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
WSADATA wsaData;
|
|
|
|
WSAStartup(MAKEWORD(1, 1), &wsaData);
|
|
|
|
name = gethostbyname(hostname);
|
2008-04-22 08:44:56 +08:00
|
|
|
#else
|
|
|
|
name = gethostbyname(hostname);
|
2008-02-01 08:50:56 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-20 05:19:00 +08:00
|
|
|
if (name == NULL) {
|
|
|
|
FreeAddrInfo(*addr_info);
|
|
|
|
*addr_info = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-02-01 08:50:56 +08:00
|
|
|
// Fill in the appropriate variables to be able to connect to the server.
|
2010-05-20 05:19:00 +08:00
|
|
|
address->sin_family = name->h_addrtype;
|
|
|
|
memcpy((char *) &address->sin_addr.s_addr,
|
2008-02-01 08:50:56 +08:00
|
|
|
name->h_addr_list[0], name->h_length);
|
2010-05-20 05:19:00 +08:00
|
|
|
address->sin_port = htons(port);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Platform independent version of getaddrinfo()
|
|
|
|
// Given a hostname:port, produce an addrinfo struct
|
|
|
|
static int GetAddrInfo(const char* hostname, int port,
|
|
|
|
struct addrinfo** address) {
|
|
|
|
#if defined(__linux__)
|
|
|
|
char port_str[40];
|
|
|
|
snprintf(port_str, 40, "%d", port);
|
|
|
|
return getaddrinfo(hostname, port_str, NULL, address);
|
|
|
|
#else
|
|
|
|
return GetAddrInfoNonLinux(hostname, port, address);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set up a connection to a ScrollView on hostname:port.
|
|
|
|
SVNetwork::SVNetwork(const char* hostname, int port) {
|
|
|
|
mutex_send_ = new SVMutex();
|
|
|
|
msg_buffer_in_ = new char[kMaxMsgSize + 1];
|
|
|
|
msg_buffer_in_[0] = '\0';
|
|
|
|
|
|
|
|
has_content = false;
|
|
|
|
buffer_ptr_ = NULL;
|
|
|
|
|
|
|
|
struct addrinfo *addr_info = NULL;
|
2008-02-01 08:50:56 +08:00
|
|
|
|
2010-05-20 05:19:00 +08:00
|
|
|
if (GetAddrInfo(hostname, port, &addr_info) != 0) {
|
|
|
|
std::cerr << "Error resolving name for ScrollView host "
|
|
|
|
<< std::string(hostname) << ":" << port << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
|
|
|
|
addr_info->ai_protocol);
|
2008-02-01 08:50:56 +08:00
|
|
|
|
|
|
|
// If server is not there, we will start a new server as local child process.
|
2010-05-20 05:19:00 +08:00
|
|
|
if (connect(stream_, addr_info->ai_addr, addr_info->ai_addrlen) < 0) {
|
2008-02-01 08:50:56 +08:00
|
|
|
const char* scrollview_path = getenv("SCROLLVIEW_PATH");
|
|
|
|
if (scrollview_path == NULL) {
|
|
|
|
#ifdef SCROLLVIEW_PATH
|
|
|
|
#define _STR(a) #a
|
|
|
|
#define _XSTR(a) _STR(a)
|
|
|
|
scrollview_path = _XSTR(SCROLLVIEW_PATH);
|
|
|
|
#undef _XSTR
|
|
|
|
#undef _STR
|
|
|
|
#else
|
|
|
|
scrollview_path = ".";
|
|
|
|
#endif
|
|
|
|
}
|
2010-05-20 05:19:00 +08:00
|
|
|
const char *prog = ScrollViewProg();
|
|
|
|
std::string command = ScrollViewCommand(scrollview_path);
|
|
|
|
SVSync::StartProcess(prog, command.c_str());
|
2008-02-01 08:50:56 +08:00
|
|
|
|
|
|
|
// Wait for server to show up.
|
|
|
|
// Note: There is no exception handling in case the server never turns up.
|
2013-02-23 19:57:40 +08:00
|
|
|
|
|
|
|
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
|
|
|
|
addr_info->ai_protocol);
|
|
|
|
|
|
|
|
while (connect(stream_, addr_info->ai_addr,
|
2010-05-20 05:19:00 +08:00
|
|
|
addr_info->ai_addrlen) < 0) {
|
2008-02-01 08:50:56 +08:00
|
|
|
std::cout << "ScrollView: Waiting for server...\n";
|
2012-03-03 01:31:24 +08:00
|
|
|
#ifdef _WIN32
|
2008-02-01 08:50:56 +08:00
|
|
|
Sleep(1000);
|
|
|
|
#else
|
|
|
|
sleep(1);
|
|
|
|
#endif
|
2013-02-23 19:57:40 +08:00
|
|
|
|
|
|
|
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
|
|
|
|
addr_info->ai_protocol);
|
2008-02-01 08:50:56 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-20 05:19:00 +08:00
|
|
|
FreeAddrInfo(addr_info);
|
2008-02-01 08:50:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SVNetwork::~SVNetwork() {
|
|
|
|
delete[] msg_buffer_in_;
|
|
|
|
delete mutex_send_;
|
|
|
|
}
|
2009-06-04 01:24:08 +08:00
|
|
|
|
|
|
|
#endif // GRAPHICS_DISABLED
|