summaryrefslogtreecommitdiff
path: root/cesar/maximus
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus')
-rw-r--r--cesar/maximus/sci/utest/server/src/TestSciServer.cpp2
-rw-r--r--cesar/maximus/sci/utest/server/src/fake_Station.cpp131
2 files changed, 63 insertions, 70 deletions
diff --git a/cesar/maximus/sci/utest/server/src/TestSciServer.cpp b/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
index 7d76ccf1f6..d21223c728 100644
--- a/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
+++ b/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
@@ -60,7 +60,7 @@ TestSciServer::test_pipe_bidir ()
server->register_current_tick_addr (&time);
Station *fake_sta = new Station (*max,
- "noexec", 0, SCI_MSG_MAX_SIZE);
+ "pipe", 0, SCI_MSG_MAX_SIZE);
sta_list.push_back (fake_sta);
PipoSciMsg *msg = NULL;
diff --git a/cesar/maximus/sci/utest/server/src/fake_Station.cpp b/cesar/maximus/sci/utest/server/src/fake_Station.cpp
index 64d76b6578..76ea919da7 100644
--- a/cesar/maximus/sci/utest/server/src/fake_Station.cpp
+++ b/cesar/maximus/sci/utest/server/src/fake_Station.cpp
@@ -38,39 +38,57 @@ Station::Station (
mStationStatus (MAXIMUS_STATION_STATUS_IDLE),
mStationIdleCounter (0)
{
- std::ostringstream pipe_max2sta, pipe_sta2max;
+ int fd_socket[PIPE_WAY_NB] = {-1, -1};
+ int fd_pipe[PIPE_WAY_NB][PIPE_NB] = {{-1, -1}, {-1, -1}};
+ bool is_socket;
- pipe_max2sta << STATION_PIPE_PATH;
- pipe_max2sta << "/" ;
- pipe_max2sta << STATION_PIPE_PREFIX;
- pipe_sta2max << pipe_max2sta.str ();
+ /* station_executable is equal to "pipe" or "socket". */
+ is_socket = (0 != station_executable.compare ("pipe") ?
+ true: false);
- pipe_sta2max << "_sta2max_";
- pipe_max2sta << "_max2sta_";
+ if (is_socket)
+ socketpair (AF_LOCAL, SOCK_STREAM, 0, fd_socket);
+ else
+ {
+ pipe (fd_pipe[PIPE_STA2MAX]);
+ pipe (fd_pipe[PIPE_MAX2STA]);
+ }
mPid = fork ();
- if (mPid == 0)
+ if (mPid == -1)
{
- /* child process. */
- mPid = getpid ();
- pipe_sta2max << std::dec << mPid;
- pipe_max2sta << std::dec << mPid;
-
- mknod (pipe_max2sta.str ().c_str (), 0770 | S_IFIFO, 0);
- mknod (pipe_sta2max.str ().c_str (), 0770 | S_IFIFO, 0);
-
- /* output pipe for a sta. */
- fd_sta2max = open (pipe_sta2max.str ().c_str (),
- O_WRONLY);
- if (fd_sta2max < 0)
- exit (EXIT_FAILURE);
+ Error e (__PRETTY_FUNCTION__, "fork failed", errno);
+ e.display ();
+ exit (EXIT_FAILURE);
+ }
+ else if (mPid == 0)
+ {
+ /* Child process. */
+ if (is_socket)
+ {
+ close (fd_socket[SOCKET_MAXIMUS]);
- /* Input pipe for a sta. */
- fd_max2sta = open (pipe_max2sta.str ().c_str (),
- O_RDONLY | O_CLOEXEC);;
- if (fd_max2sta < 0)
- exit (EXIT_FAILURE);
+ /* socket become stdout and stdin. */
+ dup2 (fd_socket[SOCKET_STA], 0);
+ dup2 (fd_socket[SOCKET_STA], 1);
+ close (fd_socket[SOCKET_STA]);
+ }
+ else
+ {
+ /* Child read on its stdin(0). */
+ close (fd_pipe[PIPE_MAX2STA][PIPE_WRITE]);
+ dup2 (fd_pipe[PIPE_MAX2STA][PIPE_READ], 0);
+ close (fd_pipe[PIPE_MAX2STA][PIPE_READ]);
+
+ /* Child write on its stdout(1). */
+ close (fd_pipe[PIPE_STA2MAX][PIPE_READ]);
+ dup2 (fd_pipe[PIPE_STA2MAX][PIPE_WRITE], 1);
+ close (fd_pipe[PIPE_STA2MAX][PIPE_WRITE]);
+ }
+
+ fd_max2sta = 0;
+ fd_sta2max = 1;
try
{
@@ -108,55 +126,30 @@ Station::Station (
/* Wait the SIGKILL. */
pause ();
+ exit (EXIT_FAILURE);
}
+ else
+ {
+ /* Parent process. */
+ if (is_socket)
+ {
+ close (fd_socket[SOCKET_STA]);
+ fd_sta2max = fd_socket[SOCKET_MAXIMUS];
+ fd_max2sta = fd_socket[SOCKET_MAXIMUS];
+ }
+ else
+ {
+ close (fd_pipe[PIPE_MAX2STA][PIPE_READ]);
+ close (fd_pipe[PIPE_STA2MAX][PIPE_WRITE]);
- assert (mPid >= 0);
-
- pipe_sta2max << std::dec << mPid;
- pipe_max2sta << std::dec << mPid;
-
- mknod (pipe_max2sta.str ().c_str (), 0770 | S_IFIFO, 0);
- mknod (pipe_sta2max.str ().c_str (), 0770 | S_IFIFO, 0);
-
- fd_sta2max = open (pipe_sta2max.str ().c_str (),
- O_RDONLY | O_CLOEXEC);;
- assert (fd_sta2max >= 0);
-
- fd_max2sta = open (pipe_max2sta.str ().c_str (),
- O_WRONLY);
- assert (fd_sta2max >= 0);
+ fd_sta2max = fd_pipe[PIPE_STA2MAX][PIPE_READ];
+ fd_max2sta = fd_pipe[PIPE_MAX2STA][PIPE_WRITE];
+ }
+ }
}
Station::~Station ()
{
- std::ostringstream pipe_max2sta, pipe_sta2max;
-
- pipe_max2sta << STATION_PIPE_PATH;
- pipe_max2sta << "/" ;
- pipe_max2sta << STATION_PIPE_PREFIX;
- pipe_sta2max << pipe_max2sta.str ();
-
- pipe_sta2max << "_sta2max_";
- pipe_max2sta << "_max2sta_";
-
- pipe_sta2max << std::dec << mPid;
- pipe_max2sta << std::dec << mPid;
-
- if (fd_max2sta >= 0)
- {
- close (fd_max2sta);
- fd_max2sta = 0;
- }
-
- if (fd_sta2max >= 0)
- {
- close (fd_sta2max);
- fd_sta2max = 0;
- }
-
- remove (pipe_sta2max.str ().c_str ());
- remove (pipe_max2sta.str ().c_str ());
-
kill (mPid, SIGKILL);
}