예제 #1
0
static int
_iostream_shutdown (struct _mu_stream *str, int how)
{
  struct _mu_iostream *sp = (struct _mu_iostream *)str;
  int rc = EINVAL;
  switch (how)
    {
    case MU_STREAM_READ:
      rc = mu_stream_shutdown (sp->transport[_MU_STREAM_INPUT], how);
      if (rc)
	sp->last_err_str = _MU_STREAM_INPUT;
      break;
      
    case MU_STREAM_WRITE:
      rc = mu_stream_shutdown (sp->transport[_MU_STREAM_OUTPUT], how);
      if (rc)
	sp->last_err_str = _MU_STREAM_OUTPUT;
    }
  return rc;
}
예제 #2
0
int
main (int argc, char * argv [])
{
  mu_stream_t in, out, sock;
  pid_t pid;
  int status, c;

  while ((c = getopt (argc, argv, "v")) != EOF)
    switch (c)
      {
      case 'v':
	verbose++;
	break;

      case 'h':
	printf ("usage: musocio file\n");
	return 0;

      default:
	return 1;
      }

  argc -= optind;
  argv += optind;
  
  if (argc != 2)
    {
      mu_error ("usage: musocio file");
      return 1;
    }

  MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0));
  mu_stream_set_buffer (in, mu_buffer_line, 0);
  MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
  mu_stream_set_buffer (out, mu_buffer_line, 0);
  MU_ASSERT (mu_socket_stream_create (&sock, argv[1], MU_STREAM_RDWR));
  mu_stream_set_buffer (sock, mu_buffer_line, 0);
  
  pid = fork ();
  if (pid == -1)
    {
      mu_error ("fork failed: %s", mu_strerror (errno));
      return 1;
    }

  if (pid == 0)
    {
      mu_stream_close (in);
      mu_stream_destroy (&in);
      ioloop ("reader", sock, out);
      exit (0);
    }

  ioloop ("writer", in, sock);

  mu_stream_close (in);
  mu_stream_destroy (&in);

  mu_stream_shutdown (sock, MU_STREAM_WRITE);
  waitpid (pid, &status, 0);

  mu_stream_close (sock);
  mu_stream_destroy (&sock);
  
  mu_stream_close (out);
  mu_stream_destroy (&out);
  return 0;
}
예제 #3
0
static int
_streamref_shutdown (struct _mu_stream *str, int how)
{
  struct _mu_streamref *sp = (struct _mu_streamref *)str;
  return streamref_return (sp, mu_stream_shutdown (sp->transport, how));
}