Exemplo n.º 1
0
static twopence_packet_t *
twopence_packet_new(twopence_buf_t *bp)
{
	twopence_packet_t *pkt;

	pkt = twopence_calloc(1, sizeof(*pkt));
	pkt->buffer = bp;
	pkt->bytes = twopence_buf_count(bp);
	return pkt;
}
Exemplo n.º 2
0
// Initialize the library
//
// This specific plugin takes the filename of a UNIX domain socket as argument
//
// Returns a "handle" that must be passed to subsequent function calls,
// or NULL in case of a problem
static struct twopence_target *
twopence_tcp_init(const char *filename)
{
  struct twopence_tcp_target *handle;

  // Allocate the opaque handle
  handle = twopence_calloc(1, sizeof(struct twopence_tcp_target));
  if (handle == NULL)
    return NULL;

  // Initialize the handle
  if (__twopence_tcp_init(handle, filename) < 0) {
    free(handle);
    return NULL;
  }

  return (struct twopence_target *) handle;
};
Exemplo n.º 3
0
static twopence_sock_t *
__twopence_socket_new(int fd, int oflags)
{
	twopence_sock_t *sock;
	int f;

	sock = twopence_calloc(1, sizeof(*sock));
	sock->fd = fd;
	sock->closeit = true;

	/* Set flags (usually for nonblocking IO) */
	if ((f = fcntl(fd, F_GETFL)) < 0
	 || fcntl(fd, F_SETFL, f | oflags) < 0) {
		twopence_log_error("socket_new: trouble setting socket to nonblocking I/O: %m\n");
		/* Continue anyway */
	}

	twopence_queue_init(&sock->xmit_queue);
	return sock;
}