summaryrefslogtreecommitdiff
path: root/cesar/maximus
diff options
context:
space:
mode:
authorCyril Jourdan2012-03-12 17:46:07 +0100
committerCyril Jourdan2012-03-30 08:15:46 +0200
commit36363b2cd0254585f555334f93aa857d2f12b6ed (patch)
tree61eaa9b10652b70477e5e84cafb5075ed8b61641 /cesar/maximus
parentb771134c4e4a32399158d7b280dec437d97f67c8 (diff)
cesar/{maximus, host}/sci: make read and write blocking, refs #2995
Diffstat (limited to 'cesar/maximus')
-rw-r--r--cesar/maximus/sci/src/SciServer.cpp50
-rw-r--r--cesar/maximus/system/src/Station.cpp4
2 files changed, 13 insertions, 41 deletions
diff --git a/cesar/maximus/sci/src/SciServer.cpp b/cesar/maximus/sci/src/SciServer.cpp
index d4116a1968..400141342a 100644
--- a/cesar/maximus/sci/src/SciServer.cpp
+++ b/cesar/maximus/sci/src/SciServer.cpp
@@ -186,17 +186,12 @@ bool SciServer::process ( )
header_len = sizeof(struct Sci_Msg_Header);
if((len = read(fd_index, &header, sizeof(struct Sci_Msg_Header))) < header_len)
{
- if (EAGAIN != errno)
- {
+ /* Read is blocking, it should never return a smaller length
+ * than the one we asked */
#if CONFIG_LOG
- clog << logger(LOG_ERROR) << "header read error: len = " << dec << len << ", errno = " << errno << endl;
+ clog << logger(LOG_ERROR) << "header read error: len = " << dec << len << ", errno = " << errno << endl;
#endif /* CONFIG_LOG */
- throw Error(__PRETTY_FUNCTION__, "Header read error: len < header_len", errno);
- }
- else
- {
- len = 0;
- }
+ throw Error(__PRETTY_FUNCTION__, "Header read error: len < header_len", errno);
}
else
{
@@ -231,19 +226,17 @@ bool SciServer::process ( )
header.netclock_low = ntohl(header.netclock_low);
header.reserved = ntohs(header.reserved);
header.flags = ntohs(header.flags);
-
+
buffer = (unsigned char *)malloc(header.length);
if((len = read(fd_index, buffer, header.length)) != header.length)
{
+ /* Read is blocking, it should never return a smaller length
+ * than the one we asked */
#if CONFIG_LOG
clog << logger(LOG_ERROR) << "data read error: len = " << dec << len << ", errno = " << errno << endl;
#endif /* CONFIG_LOG */
free(buffer);
- if (0 == len)
- {
- throw Error(__PRETTY_FUNCTION__, "Data read error: len = 0", errno);
- }
- continue;
+ throw Error(__PRETTY_FUNCTION__, "Data read error: len = 0", errno);
}
receiveMsg(&header, header.length, buffer);
free(buffer);
@@ -424,14 +417,7 @@ bool SciServer::sendSciMsg ( const SciMsg & sci_msg_to_send ) const
length = write((*it)->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
if(length < 0)
{
- if (EAGAIN != errno)
- {
- throw Error(__PRETTY_FUNCTION__, "write data failed", errno);
- }
- else
- {
- length = 0;
- }
+ throw Error(__PRETTY_FUNCTION__, "write data failed", errno);
}
totalLength += length;
}
@@ -515,14 +501,7 @@ bool SciServer::sendSciMsgToAllActiveStations ( SciMsg & sci_msg_to_send ) const
length = write((*it)->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
if(length < 0)
{
- if (EAGAIN != errno)
- {
- throw Error(__PRETTY_FUNCTION__, "write data failed", errno);
- }
- else
- {
- length = 0;
- }
+ throw Error(__PRETTY_FUNCTION__, "write data failed", errno);
}
totalLength += length;
}
@@ -620,14 +599,7 @@ bool SciServer::sendSciMsgToDestStations ( SciMsg & sci_msg_to_send, DestStation
length = write((*it)->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
if(length < 0)
{
- if (EAGAIN != errno)
- {
- throw Error(__PRETTY_FUNCTION__, "write data failed", errno);
- }
- else
- {
- length = 0;
- }
+ throw Error(__PRETTY_FUNCTION__, "write data failed", errno);
}
totalLength += length;
}
diff --git a/cesar/maximus/system/src/Station.cpp b/cesar/maximus/system/src/Station.cpp
index fba450115a..14c4ce370a 100644
--- a/cesar/maximus/system/src/Station.cpp
+++ b/cesar/maximus/system/src/Station.cpp
@@ -525,7 +525,7 @@ void Station::startProcess ( const Network_Clock_Tick current_tick_value, uint32
{
// Connect to server
//
- if((mInputFileDescriptor = open(nameBuffer, O_RDONLY | O_NONBLOCK)) >= 0)
+ if((mInputFileDescriptor = open(nameBuffer, O_RDONLY)) >= 0)
{
break;
}
@@ -543,7 +543,7 @@ void Station::startProcess ( const Network_Clock_Tick current_tick_value, uint32
// Open output pipe
sprintf(nameBuffer, "%s/%s_in_%d", STATION_PIPE_PATH, STATION_PIPE_PREFIX, getPid());
- if((mOutputFileDescriptor = open(nameBuffer, O_WRONLY | O_NONBLOCK)) < 0)
+ if((mOutputFileDescriptor = open(nameBuffer, O_WRONLY)) < 0)
{
stopProcess();
throw Error(__PRETTY_FUNCTION__, "Cannot open output pipe", errno);