Changes due to continue development of the IpcLibs. Not done yet.

This commit is contained in:
Juan Carlos Luciani
2006-09-01 05:37:43 +00:00
parent 4326223276
commit f45c0f4c9e
10 changed files with 64 additions and 215 deletions

View File

@@ -61,7 +61,7 @@ CPPFILES = channelproto.cpp \
CSFILES_CSC :=
INCLUDES = -I. -I.. -I../common -I../../../../include
RESOURCES =
DEFINES += -Wno-format-extra-args -fno-strict-aliasing
DEFINES += -Wno-format-extra-args -fno-strict-aliasing -fshort-wchar
CFLAGS += $(INCLUDES) $(DEFINES)
CPPFLAGS += $(INCLUDES) $(DEFINES)
LIBS = -lpthread -ldl -lexpat

View File

@@ -394,7 +394,7 @@ CChannel::connectionThread(
uint32_t reqId;
int payloadLength;
unsigned long totalPayloadBytesReceived = 0;
char reqDataPktHdr[sizeof(ReqDataPktHdrTemplate) - 1];
char reqDataPktHdr[ReqDataPktHdrTemplate.length()];
char *pRecvBuff;
RCMapIter iter;
ClientReq *pClientReq;
@@ -420,7 +420,7 @@ CChannel::connectionThread(
{
bytesReceived = recv(pCChannel->m_socket,
reqDataPktHdr,
sizeof(ReqDataPktHdrTemplate) - 1,
sizeof(reqDataPktHdr),
MSG_WAITALL);
if (bytesReceived == SOCKET_ERROR
&& errno == EINTR)
@@ -432,7 +432,7 @@ CChannel::connectionThread(
if (bytesReceived != SOCKET_ERROR)
{
// Check if the connection was terminated
if (bytesReceived == (sizeof(ReqDataPktHdrTemplate) - 1))
if (bytesReceived == sizeof(reqDataPktHdr))
{
// Get the payload length
if (ChannelProto::getReqIdAndPayloadLength(reqDataPktHdr,
@@ -759,7 +759,7 @@ CChannel::submitReq(
//=======================================================================--
{
int retStatus = -1;
char reqDataPktHdr[sizeof(ReqDataPktHdrTemplate) - 1];
char reqDataPktHdr[ReqDataPktHdrTemplate.length()];
struct msghdr sendmsgHdr = {0};
struct iovec ioVectors[2];
unsigned long bytesSent;
@@ -941,140 +941,6 @@ CChannel::removeReq(
} /*-- CChannel::removeReq() --*/
//++=======================================================================
int
CChannel::sendData(
uint32_t reqId,
char *pClientData,
int clientDataLen)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
int retStatus = -1;
char reqDataPktHdr[sizeof(ReqDataPktHdrTemplate) - 1];
struct msghdr sendmsgHdr = {0};
struct iovec ioVectors[2];
unsigned long bytesSent;
unsigned long totalBytesSent = 0;
unsigned long bytesToSend = sizeof(reqDataPktHdr) + clientDataLen;
DbgTrace(1, "CChannel::sendData- Start, Obj = %08X\n", this);
// Acquire exclusive access to the channel object
pthread_mutex_lock(&m_mutex);
// Verify that the channel is connected
if (m_state == State_Connected)
{
// Build ReqDataHeader
if (ChannelProto::buildReqDataPktHdr(reqId,
clientDataLen,
reqDataPktHdr) == 0)
{
// Packet header was built, now sent it along with the client data to
// the server.
ioVectors[0].iov_base = reqDataPktHdr;
ioVectors[0].iov_len = sizeof(reqDataPktHdr);
ioVectors[1].iov_base = (char*) pClientData;
ioVectors[1].iov_len = clientDataLen;
sendmsgHdr.msg_iov = ioVectors;
sendmsgHdr.msg_iovlen = 2;
while (1)
{
bytesSent = sendmsg(m_socket,
&sendmsgHdr,
MSG_NOSIGNAL);
if (bytesSent == SOCKET_ERROR)
{
// Check if we were interrupted during the transfer
if (errno == EINTR)
{
// Just try again
continue;
}
// An unrecoverable error was encountered during the send operation,
// assume there was a communication failure. Close the socket to make
// sure that the connectionThread cleans up.
DbgTrace(0, "CChannel::sendData- sendmsg error, errno = %d\n", errno);
m_state = State_Disconnected;
shutdown(m_socket, SHUT_RDWR);
struct linger linger_opt = {1, 15};
setsockopt(m_socket, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));
closesocket(m_socket);
m_socket = INVALID_SOCKET;
break;
}
else
{
// Account for the bytes sent
totalBytesSent += bytesSent;
// Check if we are done sending all of the data
if (totalBytesSent >= bytesToSend)
{
// We are done
break;
}
else
{
// Adjust the ioVector structure to send data not yet sent
if (totalBytesSent >= sizeof(reqDataPktHdr))
{
// The packet header was sent, use only one ioVector.
int clientDataAlreadySent = totalBytesSent - sizeof(reqDataPktHdr);
ioVectors[0].iov_base = (char*) pClientData + clientDataAlreadySent;
ioVectors[0].iov_len = clientDataLen - clientDataAlreadySent;
sendmsgHdr.msg_iov = ioVectors;
sendmsgHdr.msg_iovlen = 1;
}
else
{
// Not all of the packet header was sent, use two ioVectors.
ioVectors[0].iov_base = (char*) reqDataPktHdr + totalBytesSent;
ioVectors[0].iov_len = sizeof(reqDataPktHdr) - totalBytesSent;
ioVectors[1].iov_base = (char*) pClientData;
ioVectors[1].iov_len = clientDataLen;
sendmsgHdr.msg_iov = ioVectors;
sendmsgHdr.msg_iovlen = 2;
}
}
}
}
// Return success even if the send failed to allow things to be cleaned up
// by the connectionThread routine.
retStatus = 0;
}
else
{
DbgTrace(0, "CChannel::sendData- Error building Req Data Pkt Header, Obj = %08X\n", this);
}
}
else
{
DbgTrace(1, "CChannel::sendData- Channel not connected, state = %08X\n", m_state);
}
// Release exclusive access to the channel object
pthread_mutex_unlock(&m_mutex);
DbgTrace(1, "CChannel::sendData- End, retStatus = %08X\n", retStatus);
return retStatus;
} /*-- CChannel::sendData() --*/
//=========================================================================
//=========================================================================

View File

@@ -167,7 +167,7 @@ IpcClientInit(
// Note: It is necessary to call the appropriate function to
// set the server address before a request can be submitted.
//
// L0
// L1
//=======================================================================--
{
int retStatus = -1;
@@ -259,7 +259,7 @@ IpcClientSetUnAddress(
// Note: The service should have been initialized before calling
// this procedure.
//
// L0
// L1
//=======================================================================--
{
int retStatus = -1;
@@ -324,7 +324,7 @@ IpcClientSetInAddress(
// Note: The service should have been initialized before calling
// this procedure.
//
// L0
// L1
//=======================================================================--
{
int retStatus = -1;

View File

@@ -160,41 +160,20 @@ ClientReq::processServerData(
// Acquire exclusive access to the object
pthread_mutex_lock(&m_mutex);
try {
// Save server dataetup the ServerData object
m_pServerData = pServerData;
m_serverDataLen = serverDataLength;
// Save server dataetup the ServerData object
m_pServerData = pServerData;
m_serverDataLen = serverDataLength;
// Mark the request as completed
m_completed = true;
// Check if we must awaken the thread that submitted the request
// so that it can service the server data.
if (!m_submitThreadActive)
{
// The submit thread is not active, awaken it.
m_submitThreadActive = true;
pthread_cond_signal(&m_condition);
}
}
catch(...) {
DbgTrace(0, "ClientReq::processServerData- Exception caught, Obj = %08X\n", this);
// Free the server data buffer
delete[] pServerData;
// Record that we suffered an internal problem and mark the
// request as completed.
m_internalProblem = true;
m_completed = true;
// Check if we must awaken the thread that submitted the request
// so that it can deal with the problem.
if (!m_submitThreadActive)
{
// The submit thread is not active, awaken it.
m_submitThreadActive = true;
pthread_cond_signal(&m_condition);
}
// Check if we must awaken the thread that submitted the request
// so that it can service the server data.
if (!m_submitThreadActive)
{
// The submit thread is not active, awaken it.
m_submitThreadActive = true;
pthread_cond_signal(&m_condition);
}
// Release exclusive access to the object

View File

@@ -181,7 +181,7 @@ ExecuteTests(void)
if (threadCreatedCount != 0)
{
while (submitReqCount
&& !errorDatected)
&& !errorDetected)
sleep(1);
sleep(1);
}