| version 1.5, 2002/10/02 20:13:58 |
version 1.6, 2003/11/20 11:55:16 |
| Line 26 netConnection::netConnection(const char* |
|
| Line 26 netConnection::netConnection(const char* |
|
| handle=-1; |
handle=-1; |
| __rbuf=NULL; |
__rbuf=NULL; |
| setHost(host,port); |
setHost(host,port); |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"netConnection::netConnection() STATUS: Object created.\n"); |
fprintf(stderr,"netConnection::netConnection() STATUS: Object created.\n"); |
| fprintf(stderr," host: %s, port: %d, handle: %d, __rbuf: %p\n",host,port,handle,__rbuf); |
fprintf(stderr," host: %s, port: %d, handle: %d, __rbuf: %p\n",host,port,handle,__rbuf); |
| #endif |
#endif |
| Line 35 netConnection::netConnection(const char* |
|
| Line 35 netConnection::netConnection(const char* |
|
| netConnection::~netConnection(void) |
netConnection::~netConnection(void) |
| { |
{ |
| disconnect(); |
disconnect(); |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"netConnection::~netConnection() STATUS: Object destroyed.\n"); |
fprintf(stderr,"netConnection::~netConnection() STATUS: Object destroyed.\n"); |
| #endif |
#endif |
| } |
} |
| Line 69 int netConnection::connect(void) |
|
| Line 69 int netConnection::connect(void) |
|
| struct hostent*he; |
struct hostent*he; |
| |
|
| he=gethostbyname(host); |
he=gethostbyname(host); |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"netConnection::Connect()\n"); |
fprintf(stderr,"netConnection::Connect()\n"); |
| if(he==NULL) |
if(he==NULL) |
| fprintf(stderr," ERROR: Unknown host. [%s]\n",host); |
fprintf(stderr," ERROR: Unknown host. [%s]\n",host); |
| Line 79 int netConnection::connect(void) |
|
| Line 79 int netConnection::connect(void) |
|
| if(he==NULL)return(0); |
if(he==NULL)return(0); |
| |
|
| if(port<=0){ |
if(port<=0){ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," WARNING: Bad port (%d) changed to default (%d).\n",port,NET_CONNECTION_PORT); |
fprintf(stderr," WARNING: Bad port (%d) changed to default (%d).\n",port,NET_CONNECTION_PORT); |
| #endif |
#endif |
| port=NET_CONNECTION_PORT; |
port=NET_CONNECTION_PORT; |
| Line 89 int netConnection::connect(void) |
|
| Line 89 int netConnection::connect(void) |
|
| sin.sin_addr.s_addr=*((unsigned int*)he->h_addr); |
sin.sin_addr.s_addr=*((unsigned int*)he->h_addr); |
| sin.sin_port=htons(port); |
sin.sin_port=htons(port); |
| handle=socket(PF_INET,SOCK_STREAM,0); |
handle=socket(PF_INET,SOCK_STREAM,0); |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| if(handle==-1)fprintf(stderr," ERROR: Can't create socket.\n"); |
if(handle==-1)fprintf(stderr," ERROR: Can't create socket.\n"); |
| else |
else |
| fprintf(stderr," OK: Socket created.\n"); |
fprintf(stderr," OK: Socket created.\n"); |
| #endif |
#endif |
| if(handle==-1)return(0); |
if(handle==-1)return(0); |
| |
|
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," STATUS: Trying to connect...\n"); |
fprintf(stderr," STATUS: Trying to connect...\n"); |
| #endif |
#endif |
| /* We want connect() syscall, not netConnection method */ |
/* We want connect() syscall, not netConnection method */ |
| if(::connect(handle,(struct sockaddr*)&sin,sizeof(struct sockaddr_in))==-1){ |
if(::connect(handle,(struct sockaddr*)&sin,sizeof(struct sockaddr_in))==-1){ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," ERROR: Cannot connect.\n"); |
fprintf(stderr," ERROR: Cannot connect.\n"); |
| #endif |
#endif |
| return(0); |
return(0); |
| } |
} |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr," OK: Connection estabilished.\n"); |
fprintf(stderr," OK: Connection estabilished.\n"); |
| #endif |
#endif |
| #endif |
#endif |
| Line 116 int netConnection::connect(void) |
|
| Line 116 int netConnection::connect(void) |
|
| |
|
| void netConnection::disconnect(void){ |
void netConnection::disconnect(void){ |
| if(handle<0){ |
if(handle<0){ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"netConnection::disconnect() WARNING: Handle not opened, already closed. [%d]\n",handle); |
fprintf(stderr,"netConnection::disconnect() WARNING: Handle not opened, already closed. [%d]\n",handle); |
| #endif |
#endif |
| } |
} |
| else{ |
else{ |
| if(close(handle)==-1){ |
if(close(handle)==-1){ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"netConnection::disconnect() WARNING: Cannot close handle. [%d]\n",handle); |
fprintf(stderr,"netConnection::disconnect() WARNING: Cannot close handle. [%d]\n",handle); |
| #endif |
#endif |
| } |
} |
| else{ |
else{ |
| #if DEBUG |
#if NET_CONNECTION_DEBUG |
| fprintf(stderr,"netConnection::disconnect() OK: Handle closed. [%d]\n",handle); |
fprintf(stderr,"netConnection::disconnect() OK: Handle closed. [%d]\n",handle); |
| #endif |
#endif |
| } |
} |