Exemplo n.º 1
0
int rdr_repeater_step(struct rdr_repeater_ctx_t *ctx, fd_set *readfds, fd_set *writefds)
{
   struct endpoint_t *ep;

   assert(ctx);
   assert(readfds);
   assert(writefds);

   for (ep = ctx->head; ep != NULL; ep = ep->next) {
      switch (ep->status) {
	 case S_CONNECTING:
	    assert(ep->s >= 0);

	    if (!FD_ISSET(ep->s, writefds))
	       break;

	    /* Socket ready for writing */
	    if (finish_socket_opening(ctx, ep) < 0) {
	       try_reopen_socket(ctx, ep);
	    }
	    break;
	 case S_WRITING:
	    assert(ep->s >= 0);

	    if (FD_ISSET(ep->s, readfds)) {
	       ssize_t rcvd;
	       unsigned char buf[1];
	       tcflush(ep->s, TCIFLUSH);
	       rcvd = read(ep->s, &buf, 1);
	       if (rcvd == 0) {
		  if (ctx->verbose)
		     fprintf(stderr, "%s Connection %s closed \n", TAG, get_endpoint_name(ep));
		  try_reopen_socket(ctx, ep);
		  break;
	       }else if (rcvd < 0) {
		  if (errno != EAGAIN && (errno != EINTR)) {
		     if (ctx->verbose)
			fprintf(stderr, "%s %s read() error: %s\n", TAG, get_endpoint_name(ep), strerror(errno));
		     try_reopen_socket(ctx, ep);
		     break;
		  }
	       }
	    }

	    if (FD_ISSET(ep->s, writefds))
	       buffered_write(ctx, ep, NULL, 0);
	    break;
	 case S_WAITING:
	    try_reopen_socket(ctx, ep);
	    break;
	 case S_NOT_INITIALIZED:
	 default:
	    /* UNREACHABLE  */
	    assert(0);
	    break;
      }
   }

   return 1;
}
Exemplo n.º 2
0
void rdr_repeater_append(struct rdr_repeater_ctx_t *ctx, void *data, size_t data_size)
{
   struct endpoint_t *ep;

   assert(ctx);

   for (ep = ctx->head; ep != NULL; ep = ep->next) {
      buffered_write(ctx, ep, data, data_size);
   }

}
Exemplo n.º 3
0
/**
 * sockprintf : a socket writting printf()
 * @param s Socket
 * @param fmt format of message
 * @param ... various args
 * @return int
 */
int sockprintf(ano_socket_t s, char *fmt, ...)
{
    va_list args;
    char buf[16384];            /* Really huge, to try and avoid truncation */
    int value;

    va_start(args, fmt);
    value = buffered_write(s, buf, vsnprintf(buf, sizeof(buf), fmt, args));
    va_end(args);
    return value;
}
Exemplo n.º 4
0
void
writecheck(
	void *buffer,
	size_t size,
	int msgNum)
{
	size_t nput;
	char    msgbuf[MAX_MSGBUF_SIZE];	/* sysevent message buffer */

	if ((nput = buffered_write(CSD_fd, buffer, size)) != size) {
		char	*explanation;

		explanation = catgets(catfd, SET, msgNum, "??");
		/* Send sysevent to generate SNMP trap */
		snprintf(msgbuf, sizeof (msgbuf), catgets(catfd, SET, 13501,
		    "Could only write %d bytes to samfsdump file, "
		    "tried %d, %s"),
		    nput, size, explanation);
		PostEvent(MISC_CLASS, "IncompleteWrite", 13501, LOG_ERR,
		    msgbuf,
		    NOTIFY_AS_FAULT | NOTIFY_AS_TRAP);
		error(1, errno, "%s", msgbuf);
	}
}
Exemplo n.º 5
0
/**
 * sputs : write buffer
 * @param s Socket
 * @param str Buffer to write
 * @return int
 */
int sputs(char *str, ano_socket_t s)
{
    return buffered_write(s, str, strlen(str));
}