Commit 9f4df1e7 authored by claes's avatar claes

Fixed several bugs

parent 87dd268b
/* /*
* Proview $Id: rs_remote_tcpip.c,v 1.3 2006-04-24 13:22:24 claes Exp $ * Proview $Id: rs_remote_tcpip.c,v 1.4 2007-11-15 14:57:44 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -310,11 +310,12 @@ void Shutdown() ...@@ -310,11 +310,12 @@ void Shutdown()
{ {
int sts; int sts;
if (cs_mode == TCP_SERVER) {
sts = close(c_socket);
} else {
sts = shutdown(c_socket, 2); sts = shutdown(c_socket, 2);
if (debug) printf("shutdown: %d\n", sts); if (debug) printf("shutdown: %d\n", sts);
if (debug && (sts < 0)) perror("shutdown"); if (debug && (sts < 0)) perror("shutdown");
if (cs_mode == TCP_CLIENT) {
sts = close(c_socket); sts = close(c_socket);
if (debug) printf("close: %d\n", sts); if (debug) printf("close: %d\n", sts);
if (debug && (sts < 0)) perror("close"); if (debug && (sts < 0)) perror("close");
...@@ -325,7 +326,7 @@ void Shutdown() ...@@ -325,7 +326,7 @@ void Shutdown()
/************************************************************************* /*************************************************************************
************************************************************************** **************************************************************************
* *
* Namn : TreatRemtrans * Namn : TreatRemtrans1
* *
* Typ : unsigned int * Typ : unsigned int
* *
...@@ -336,7 +337,7 @@ void Shutdown() ...@@ -336,7 +337,7 @@ void Shutdown()
************************************************************************** **************************************************************************
**************************************************************************/ **************************************************************************/
void TreatRemtrans(char *buf) void TreatRemtrans1(char *buf)
{ {
remtrans_item *remtrans; remtrans_item *remtrans;
unsigned char search_remtrans; unsigned char search_remtrans;
...@@ -371,6 +372,43 @@ void TreatRemtrans(char *buf) ...@@ -371,6 +372,43 @@ void TreatRemtrans(char *buf)
if (search_remtrans) rn_tcp->ErrCount++; if (search_remtrans) rn_tcp->ErrCount++;
return; return;
} }
/*************************************************************************
**************************************************************************
*
* Namn : TreatRemtrans2
*
* Typ : unsigned int
*
* Typ Parameter IOGF Beskrivning
*
* Beskrivning :
*
**************************************************************************
**************************************************************************/
void TreatRemtrans2(char *buf, int size)
{
remtrans_item *remtrans;
unsigned char search_remtrans;
unsigned int sts;
/* Start searching remtrans */
remtrans = rn.remtrans;
search_remtrans = true;
while(remtrans && search_remtrans)
{
/* Match? */
if (remtrans->objp->Direction == REMTRANS_IN)
{
search_remtrans = false;
sts = RemTrans_Receive(remtrans, buf, size);
}
remtrans = (remtrans_item *) remtrans->next;
}
if (search_remtrans) rn_tcp->ErrCount++;
return;
}
/************************************************************************* /*************************************************************************
************************************************************************** **************************************************************************
...@@ -431,7 +469,7 @@ unsigned int Receive() ...@@ -431,7 +469,7 @@ unsigned int Receive()
{ {
memcpy(&saved_buffer[saved_size], &receive_buffer, expected_rest); memcpy(&saved_buffer[saved_size], &receive_buffer, expected_rest);
TreatRemtrans(saved_buffer); TreatRemtrans1(saved_buffer);
/* Set position in data buffer */ /* Set position in data buffer */
...@@ -444,7 +482,13 @@ unsigned int Receive() ...@@ -444,7 +482,13 @@ unsigned int Receive()
while (more_messages) while (more_messages)
{ {
if (data_size >= sizeof(remote_tcp_header)) if (data_size > 0 && rn_tcp->DisableHeader) {
/* Header disabled, take the first receive remtrans object */
TreatRemtrans2(receive_buffer, data_size);
}
else if (data_size >= sizeof(remote_tcp_header))
{ {
memcpy(&header, &receive_buffer[buf_ix], sizeof(remote_tcp_header)); memcpy(&header, &receive_buffer[buf_ix], sizeof(remote_tcp_header));
...@@ -461,7 +505,7 @@ unsigned int Receive() ...@@ -461,7 +505,7 @@ unsigned int Receive()
{ {
if (header.msg_size > sizeof(header)) /* Not keepalive buffer */ if (header.msg_size > sizeof(header)) /* Not keepalive buffer */
{ {
TreatRemtrans(&receive_buffer[buf_ix]); TreatRemtrans1(&receive_buffer[buf_ix]);
} }
else if (header.msg_size == sizeof(header)) /* Keepalive buffer */ else if (header.msg_size == sizeof(header)) /* Keepalive buffer */
rn_tcp->KeepaliveDiff--; rn_tcp->KeepaliveDiff--;
...@@ -483,7 +527,7 @@ unsigned int Receive() ...@@ -483,7 +527,7 @@ unsigned int Receive()
else /* Too short */ else /* Too short */
rn_tcp->ErrCount++; rn_tcp->ErrCount++;
if (header.msg_size > 0 && !saved_fl) if (!rn_tcp->DisableHeader && header.msg_size > 0 && !saved_fl)
{ {
data_size -= header.msg_size; data_size -= header.msg_size;
buf_ix += header.msg_size; buf_ix += header.msg_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment