Skip to content
Snippets Groups Projects
Commit 412864a5 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

*** empty log message ***

parent 46094ed5
Branches
Tags
No related merge requests found
...@@ -39,14 +39,24 @@ int WaitForData(int socket, int num, int pollint, double waitint); ...@@ -39,14 +39,24 @@ int WaitForData(int socket, int num, int pollint, double waitint);
#if defined(_AIX) #if defined(_AIX)
#include <strings.h> #include <strings.h>
#endif #endif
#if !defined(WIN32) || defined(__CYGWIN__)
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/poll.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <netinet/in.h> #include <netinet/in.h>
#else // pure windows
#include <winsock2.h>
#endif
class GmshServer { class GmshServer {
public: public:
// This should match what's in GmshClient.h // This should match what's in GmshClient.h
...@@ -74,7 +84,7 @@ class GmshServer { ...@@ -74,7 +84,7 @@ class GmshServer {
int sofar = 0; int sofar = 0;
int remaining = bytes; int remaining = bytes;
do { do {
int len = read(_sock, buf + sofar, remaining); ssize_t len = recv(_sock, buf + sofar, remaining, 0);
if(len <= 0) if(len <= 0)
return 0; return 0;
sofar += len; sofar += len;
...@@ -132,7 +142,9 @@ class GmshServer { ...@@ -132,7 +142,9 @@ class GmshServer {
if(_portno < 0){ if(_portno < 0){
// delete the file if it already exists // delete the file if it already exists
#if !defined(WIN32) || defined(__CYGWIN__)
unlink(_sockname); unlink(_sockname);
#endif
// make the socket // make the socket
s = socket(PF_UNIX, SOCK_STREAM, 0); s = socket(PF_UNIX, SOCK_STREAM, 0);
...@@ -218,8 +230,10 @@ class GmshServer { ...@@ -218,8 +230,10 @@ class GmshServer {
{ {
if(_portno < 0){ if(_portno < 0){
// UNIX socket // UNIX socket
#if !defined(WIN32) || defined(__CYGWIN__)
if(unlink(_sockname) == -1) if(unlink(_sockname) == -1)
return -1; // Impossible to unlink the socket return -1; // Impossible to unlink the socket
#endif
} }
close(_sock); close(_sock);
return 0; return 0;
......
// $Id: Solvers.cpp,v 1.39 2005-08-31 21:44:44 geuzaine Exp $ // $Id: Solvers.cpp,v 1.40 2005-09-25 18:51:27 geuzaine Exp $
// //
// Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
// //
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
SolverInfo SINFO[MAXSOLVERS]; SolverInfo SINFO[MAXSOLVERS];
#if !defined(WIN32) || defined(__CYGWIN__)
#include "GmshServer.h" #include "GmshServer.h"
// FIXME: this should be removed (and we should set the socket options // FIXME: this should be removed (and we should set the socket options
...@@ -33,13 +31,6 @@ SolverInfo SINFO[MAXSOLVERS]; ...@@ -33,13 +31,6 @@ SolverInfo SINFO[MAXSOLVERS];
int GmshServer::init = 0; int GmshServer::init = 0;
int GmshServer::s; int GmshServer::s;
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/poll.h>
#include <sys/un.h>
#include <unistd.h>
#include "OpenFile.h" #include "OpenFile.h"
#include "GmshUI.h" #include "GmshUI.h"
#include "GUI.h" #include "GUI.h"
...@@ -281,13 +272,3 @@ int Solver(int num, char *args) ...@@ -281,13 +272,3 @@ int Solver(int num, char *args)
return 1; return 1;
} }
#else // pure windows
int Solver(int num, char *args)
{
Msg(GERROR, "Solver interface not available on Windows without Cygwin");
return 1;
}
#endif
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#ifdef _AIX #ifdef _AIX
#include <strings.h> #include <strings.h>
#endif #endif
#if !defined(WIN32) || defined(__CYGWIN__)
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -42,6 +45,12 @@ ...@@ -42,6 +45,12 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#else // pure windows
#include <winsock2.h>
#endif
class GmshClient { class GmshClient {
private: private:
typedef enum{ CLIENT_START = 1, typedef enum{ CLIENT_START = 1,
...@@ -63,7 +72,7 @@ class GmshClient { ...@@ -63,7 +72,7 @@ class GmshClient {
int sofar = 0; int sofar = 0;
int remaining = bytes; int remaining = bytes;
do { do {
int len = write(_sock, buf + sofar, remaining); ssize_t len = send(_sock, buf + sofar, remaining, 0);
sofar += len; sofar += len;
remaining -= len; remaining -= len;
} while(remaining > 0); } while(remaining > 0);
...@@ -77,17 +86,23 @@ class GmshClient { ...@@ -77,17 +86,23 @@ class GmshClient {
} }
long _GetTime() long _GetTime()
{ {
#if !defined(WIN32) || defined(__CYGWIN__)
struct timeval tp; struct timeval tp;
gettimeofday(&tp, (struct timezone *)0); gettimeofday(&tp, (struct timezone *)0);
return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec;
#else
return 0;
#endif
} }
void _Idle(double delay) void _Idle(double delay)
{ {
#if !defined(WIN32) || defined(__CYGWIN__)
long t1 = _GetTime(); long t1 = _GetTime();
while(1) { while(1) {
if(_GetTime() - t1 > 1.e6 * delay) if(_GetTime() - t1 > 1.e6 * delay)
break; break;
} }
#endif
} }
public: public:
GmshClient() : _sock(0) {} GmshClient() : _sock(0) {}
......
/* $Id: GmshClient.c,v 1.3 2005-01-16 20:56:03 geuzaine Exp $ */ /* $Id: GmshClient.c,v 1.4 2005-09-25 18:51:27 geuzaine Exp $ */
/* /*
* Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle * Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
* *
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
#ifdef _AIX #ifdef _AIX
#include <strings.h> #include <strings.h>
#endif #endif
#if !defined(WIN32) || defined(__CYGWIN__)
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -45,17 +48,24 @@ ...@@ -45,17 +48,24 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#else /* pure windows */
#include <winsock2.h>
#endif
/* private functions */ /* private functions */
static void Socket_SendData(int socket, void *buffer, int bytes) static void Socket_SendData(int socket, void *buffer, int bytes)
{ {
int sofar, remaining, len; ssize_t len;
int sofar, remaining;
char *buf; char *buf;
buf = (char *)buffer; buf = (char *)buffer;
sofar = 0; sofar = 0;
remaining = bytes; remaining = bytes;
do { do {
len = write(socket, buf + sofar, remaining); len = send(socket, buf + sofar, remaining, 0);
sofar += len; sofar += len;
remaining -= len; remaining -= len;
} while(remaining > 0); } while(remaining > 0);
...@@ -63,18 +73,24 @@ static void Socket_SendData(int socket, void *buffer, int bytes) ...@@ -63,18 +73,24 @@ static void Socket_SendData(int socket, void *buffer, int bytes)
static long Socket_GetTime() static long Socket_GetTime()
{ {
#if !defined(WIN32) || defined(__CYGWIN__)
struct timeval tp; struct timeval tp;
gettimeofday(&tp, (struct timezone *)0); gettimeofday(&tp, (struct timezone *)0);
return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec;
#else
return 0;
#endif
} }
static void Socket_Idle(double delay) static void Socket_Idle(double delay)
{ {
#if !defined(WIN32) || defined(__CYGWIN__)
long t1 = Socket_GetTime(); long t1 = Socket_GetTime();
while(1) { while(1) {
if(Socket_GetTime() - t1 > 1.e6 * delay) if(Socket_GetTime() - t1 > 1.e6 * delay)
break; break;
} }
#endif
} }
/* public interface */ /* public interface */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment