Ejemplo n.º 1
0
static int
zebra_server_send_message(struct zserv *client)
{
  if (client->t_suicide)
    return -1;
  switch (buffer_write(client->wb, client->sock, STREAM_DATA(client->obuf),
		       stream_get_endp(client->obuf)))
    {
    case BUFFER_ERROR:
      zlog_warn("%s: buffer_write failed to zserv client fd %d, closing",
      		 __func__, client->sock);
      /* Schedule a delayed close since many of the functions that call this
         one do not check the return code.  They do not allow for the
	 possibility that an I/O error may have caused the client to be
	 deleted. */
      client->t_suicide = thread_add_event(zebrad.master, zserv_delayed_close,
					   client, 0);
      return -1;
    case BUFFER_EMPTY:
      THREAD_OFF(client->t_write);
      break;
    case BUFFER_PENDING:
      THREAD_WRITE_ON(zebrad.master, client->t_write,
		      zserv_flush_data, client, client->sock);
      break;
    }
  return 0;
}
Ejemplo n.º 2
0
Archivo: zserv.c Proyecto: OPSF/uClinux
/* Enqueu message.  */
void
zebra_server_enqueue (int sock, u_char *buf, unsigned long length,
		      unsigned long written)
{
  struct zebra_message_queue *queue;

  queue = XCALLOC (MTYPE_TMP, sizeof (struct zebra_message_queue));
  queue->buf = XMALLOC (MTYPE_TMP, length);
  memcpy (queue->buf, buf, length);
  queue->length = length;
  queue->written = written;

  FIFO_ADD (&message_queue, queue);

  THREAD_WRITE_ON (zebrad.master, t_write, zebra_server_dequeue, NULL, sock);
}
Ejemplo n.º 3
0
Archivo: zserv.c Proyecto: OPSF/uClinux
int
zebra_server_dequeue (struct thread *t)
{
  int sock;
  int nbytes;
  struct zebra_message_queue *queue;

  sock = THREAD_FD (t);
  t_write = NULL;

  queue = (struct zebra_message_queue *) FIFO_HEAD (&message_queue);
  if (queue)
    {
      nbytes = write (sock, queue->buf + queue->written,
		      queue->length - queue->written);

      if (nbytes <= 0)
        {
          if (errno != EAGAIN)
	    return -1;
        }
      else if (nbytes != (queue->length - queue->written))
	{
	  queue->written += nbytes;
	}
      else
        {
          FIFO_DEL (queue);
          XFREE (MTYPE_TMP, queue->buf);
          XFREE (MTYPE_TMP, queue);
        }
    }

  if (FIFO_TOP (&message_queue))
    THREAD_WRITE_ON (zebrad.master, t_write, zebra_server_dequeue, 
                     NULL, sock);

  return 0;
}
Ejemplo n.º 4
0
int
svz_tunnel_send_message (struct tclient * tclient)
{
  if (tclient->sock < 0)
    return -1;
  switch(buffer_write(tclient->wb, tclient->sock, STREAM_DATA(tclient->obuf) + stream_get_getp(tclient->obuf),
                      stream_get_endp(tclient->obuf) - stream_get_getp(tclient->obuf)))
  {
    case BUFFER_ERROR:
      zlog_warn("%s: buffer_write failed to tclient fd %d, closing",
                __func__, tclient->sock);
      return svz_tunnel_failed(tclient);
    case BUFFER_EMPTY:
      THREAD_OFF(tclient->t_write);
      break;
    case BUFFER_PENDING:
      THREAD_WRITE_ON(master, tclient->t_write, 
                      svz_tunnel_flush_data, tclient, tclient->sock);
      break;
  }
  return 0;
}
Ejemplo n.º 5
0
int
zclient_send_message(struct zclient *zclient)
{
  if (zclient->sock < 0)
    return -1;
  switch (buffer_write(zclient->wb, zclient->sock, STREAM_DATA(zclient->obuf),
		       stream_get_endp(zclient->obuf)))
    {
    case BUFFER_ERROR:
      zlog_warn("%s: buffer_write failed to zclient fd %d, closing",
      		 __func__, zclient->sock);
      return zclient_failed(zclient);
      break;
    case BUFFER_EMPTY:
      THREAD_OFF(zclient->t_write);
      break;
    case BUFFER_PENDING:
      THREAD_WRITE_ON(master, zclient->t_write,
		      zclient_flush_data, zclient, zclient->sock);
      break;
    }
  return 0;
}