|
From: Marek P. <ma...@us...> - 2001-08-09 23:22:58
|
Update of /cvsroot/javaprofiler/library/src/commun
In directory usw-pr-cvs1:/tmp/cvs-serv7456/src/commun
Modified Files:
communSocket.cpp communSocket.h iprof.cpp iprof.h
Log Message:
no message
Index: communSocket.cpp
===================================================================
RCS file: /cvsroot/javaprofiler/library/src/commun/communSocket.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** communSocket.cpp 2001/07/28 23:25:47 1.3
--- communSocket.cpp 2001/08/09 23:22:55 1.4
***************
*** 1,5 ****
#include "../main/includes.h"
! CommunSocket::CommunSocket( unsigned short port) {
#ifdef WIN32
--- 1,10 ----
#include "../main/includes.h"
! CommunSocket::CommunSocket( int listenMode, const String& hostname,
! unsigned short port) :
! _listenMode( listenMode),
! _hostname( hostname),
! _port( port),
! _csock( -1) {
#ifdef WIN32
***************
*** 9,12 ****
--- 14,23 ----
if( _failed = ((_sock = socket( AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)) return;
+ if( _listenMode) {
+
+ _csock = _sock;
+ return;
+ }
+
SOCKADDR_IN sin;
sin.sin_family = AF_INET;
***************
*** 20,23 ****
--- 31,40 ----
if( _failed = ((_sock = socket( PF_INET, SOCK_STREAM, 0)) < 0)) return;
+ if( _listenMode) {
+
+ _csock = _sock;
+ return;
+ }
+
sockaddr_in sin;
sin.sin_family = AF_INET;
***************
*** 29,34 ****
if( _failed = (listen( _sock, 1) < 0)) return;
#endif
-
- _csock = -1;
}
--- 46,49 ----
***************
*** 36,42 ****
#ifdef WIN32
- shutdown( _sock, SD_BOTH);
- closesocket( _sock);
shutdown( _csock, SD_BOTH);
closesocket( _csock);
--- 51,61 ----
#ifdef WIN32
+ if( !_listenMode) {
+
+ shutdown( _sock, SD_BOTH);
+ closesocket( _sock);
+ }
+
shutdown( _csock, SD_BOTH);
closesocket( _csock);
***************
*** 44,49 ****
WSACleanup();
#else
! shutdown( _sock, SHUT_RDWR);
! close( _sock);
shutdown( _csock, SHUT_RDWR);
--- 63,72 ----
WSACleanup();
#else
!
! if( !_listenMode) {
!
! shutdown( _sock, SHUT_RDWR);
! close( _sock);
! }
shutdown( _csock, SHUT_RDWR);
***************
*** 57,67 ****
SOCKADDR_IN cin;
int csize = sizeof( cin);
! if( _failed = ((_csock = accept( _sock, (sockaddr*)&cin, &csize)) == INVALID_SOCKET)) return 0;
#else
sockaddr_in cin;
socklen_t csize = sizeof( cin);
! if( _failed = ((_csock = accept( _sock, (sockaddr*)&cin, &csize)) < 0)) return 0;
#endif
--- 80,120 ----
SOCKADDR_IN cin;
int csize = sizeof( cin);
+
+ if( !_listenMode) {
+
+ if( _failed = ((_csock = accept( _sock, (sockaddr*)&cin, &csize)) == INVALID_SOCKET)) return 0;
+ }
+ else {
+
+ cin.sin_family = AF_INET;
+ cin.sin_port = htons( _port);
+
+ hostent* h = gethostbyname( _hostname);
+ if( _failed = (h == NULL)) return 0;
! cin.sin_addr.s_addr = (unsigned)atol( h->h_addr_list[0]);
!
! if( _failed = (connect( _csock, (sockaddr*)&cin, csize) == SOCKET_ERROR)) return 0;
! }
#else
sockaddr_in cin;
socklen_t csize = sizeof( cin);
+
+ if( !_listenMode) {
+
+ if( _failed = ((_csock = accept( _sock, (sockaddr*)&cin, &csize)) < 0)) return 0;
+ }
+ else {
+
+ cin.sin_family = AF_INET;
+ cin.sin_port = htons( _port);
+
+ hostent* h = gethostbyname( _hostname);
+ if( _failed = (h == NULL)) return 0;
+
+ cin.sin_addr.s_addr = (unsigned)atol( h->h_addr_list[0]);
! if( _failed = (connect( _csock, (sockaddr*)&cin, csize) < 0)) return 0;
! }
#endif
Index: communSocket.h
===================================================================
RCS file: /cvsroot/javaprofiler/library/src/commun/communSocket.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** communSocket.h 2001/07/28 23:25:47 1.3
--- communSocket.h 2001/08/09 23:22:55 1.4
***************
*** 28,31 ****
--- 28,40 ----
#endif
+ /// hostname (if listenMode is on)
+ String _hostname;
+
+ /// port number
+ unsigned short _port;
+
+ /// listening connector mode (1 = on, 0 = off)
+ int _listenMode;
+
public:
***************
*** 33,39 ****
** on given port.
**
! ** @param port port number */
! CommunSocket( unsigned short port);
/** Destructor. It stops communication and
--- 42,51 ----
** on given port.
**
! ** @param listenMode listening connector mode
! ** @param hostname hostname (if listenMode is on)
! ** @param port port number */
! CommunSocket( int listenMode, const String& hostname,
! unsigned short port);
/** Destructor. It stops communication and
Index: iprof.cpp
===================================================================
RCS file: /cvsroot/javaprofiler/library/src/commun/iprof.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** iprof.cpp 2001/08/05 01:37:10 1.3
--- iprof.cpp 2001/08/09 23:22:55 1.4
***************
*** 3,7 ****
Allocator IProf::sID::_allocator( sizeof( IProf::sID));
! IProf::IProf( IProf::eCommunType ctype) :
communLock( "_commun_lock"),
--- 3,7 ----
Allocator IProf::sID::_allocator( sizeof( IProf::sID));
! IProf::IProf( const Setup& setup) :
communLock( "_commun_lock"),
***************
*** 21,26 ****
_func[F_IDLE] = &IProf::_idle;
! if( ctype == COMMUN_SOCKET) _commun = new CommunSocket( COMMUN_PORT);
! else _commun = new CommunSocket( COMMUN_PORT); // will be replaced by CommunShMem
}
--- 21,31 ----
_func[F_IDLE] = &IProf::_idle;
! if( setup.com.communType == COMMUN_SOCKET)
!
! _commun = new CommunSocket( setup.com.listenMode,
! setup.com.hostname,
! setup.com.port);
!
! else _commun = new CommunShMem( setup.com.shmemStr, setup.com.shmemSize);
}
***************
*** 33,37 ****
conEstabl = 0;
! if( !_commun->initialize()) return 0;
conEstabl = 1;
--- 38,42 ----
conEstabl = 0;
! if( _commun->hasFailed() || !_commun->initialize()) return 0;
conEstabl = 1;
Index: iprof.h
===================================================================
RCS file: /cvsroot/javaprofiler/library/src/commun/iprof.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** iprof.h 2001/08/05 01:37:10 1.7
--- iprof.h 2001/08/09 23:22:55 1.8
***************
*** 18,21 ****
--- 18,23 ----
typedef void (IProf::*Func)( Buffer&);
+ public:
+
/// constants
enum e {
***************
*** 24,31 ****
--- 26,38 ----
COMMUN_PORT = 25595,
+ /// default shared memory size (in bytes)
+ COMMUN_SHMEM_SIZE = 256*1024,
+
/// number of methods of the interface
FUNC_COUNT = 10
};
+ private:
+
/// an array of relative pointers to methods
Func _func[FUNC_COUNT];
***************
*** 44,48 ****
typedef jint objectID;
! protected:
/// type of communication
--- 51,55 ----
typedef jint objectID;
! public:
/// type of communication
***************
*** 56,59 ****
--- 63,68 ----
};
+ protected:
+
/// error codes
enum eErrorCode {
***************
*** 333,342 ****
/** Constructor. It initializes communication. In this moment,
! ** only socket (TCP) communication is supported and will be used
! ** in all cases.
**
! ** @param ctype type of communication */
! IProf( eCommunType ctype);
/** Destructor. It stops communication and closes
--- 342,351 ----
/** Constructor. It initializes communication. In this moment,
! ** socket (TCP) communication and shared memory communication are
! ** supported.
**
! ** @param setup commun setup */
! IProf( const Setup& setup);
/** Destructor. It stops communication and closes
|