Exemple #1
0
static int
nntp_folder_open (mu_folder_t folder, int flags)
{
  f_nntp_t f_nntp = folder->data;
  mu_stream_t carrier = NULL;
  const char *host;
  unsigned port = MU_NNTP_DEFAULT_PORT; /* default nntp port.  */
  int status = 0;

  /* If we are already open for business, noop.  */
  mu_monitor_wrlock (folder->monitor);
  if (f_nntp->isopen)
    {
      mu_monitor_unlock (folder->monitor);
      return 0;
    }
  mu_monitor_unlock (folder->monitor);

  /* Fetch the server name and the port in the mu_url_t.  */
  status = mu_url_sget_host (folder->url, &host);
  if (status != 0)
    return status;
  mu_url_get_port (folder->url, &port);

  folder->flags = flags;

  /* Create the networking stack.  */
  status = mu_tcp_stream_create (&carrier, host, port, folder->flags);
  if (status != 0)
    return status;
  /* Ask for the stream internal buffering mechanism scheme.  */
  mu_stream_setbufsiz (carrier, BUFSIZ);
  mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_PROT, ("folder_nntp_open (%s:%ld)", 
             host, port));

  status = mu_nntp_create (&f_nntp->nntp);
  if (status == 0)
    {
      status = mu_nntp_set_carrier (f_nntp->nntp, carrier);
      if (status == 0)
	{
	  status = mu_nntp_connect (f_nntp->nntp);
	  if (status == 0)
	    {
	      mu_monitor_wrlock (folder->monitor);
	      f_nntp->isopen++;
	      mu_monitor_unlock (folder->monitor);
	    }
	}
    }

  return status;
}
Exemple #2
0
static PyObject *
api_tcp_stream_create (PyObject *self, PyObject *args)
{
  int status, flags, port;
  char *host;
  PyStream *py_stm;

  if (!PyArg_ParseTuple (args, "O!sii", &PyStreamType, &py_stm,
			 &host, &port, &flags))
    return NULL;

  status = mu_tcp_stream_create (&py_stm->stm, host, port, flags);
  return _ro (PyInt_FromLong (status));
}