Exemplo n.º 1
0
/*
 * an option for gfarm_iobuffer_set_write_close()
 */
#if 0 /* currently not used */
void
gfarm_iobuffer_write_close_secsession_op(struct gfarm_iobuffer *b,
	void *cookie, int fd)
{
	struct io_gfsl *io = cookie;
	gfarm_error_t e = gfp_iobuffer_close_secsession_op(io, fd);

	if (e != GFARM_ERR_NO_ERROR && gfarm_iobuffer_get_error(b) == 0)
		gfarm_iobuffer_set_error(b, e);
}
Exemplo n.º 2
0
char *
xxx_write_direct(struct xxx_connection *conn, void *data, int length,
	int *resultp)
{
	int rv = (*conn->iob_ops->blocking_write)(conn->sendbuffer,
	    conn->cookie, conn->fd, data, length);

	if (rv == -1) {
		*resultp = 0;
		return (gfarm_iobuffer_get_error(conn->sendbuffer));
	}
	*resultp = rv;
	return (NULL);
}
Exemplo n.º 3
0
char *
xxx_proto_vsend(struct xxx_connection *conn, char **formatp, va_list *app)
{
	char *format = *formatp;
	va_list ap;
	gfarm_uint8_t c;
	gfarm_int16_t h;
	gfarm_int32_t i, n;
	file_offset_t o;
	gfarm_uint32_t ov[2];
#if FILE_OFFSET_T_IS_FLOAT
	int minus;
#endif
	char *s;

	va_copy(ap, *app);
	for (; *format; format++) {
		switch (*format) {
		case 'c':
			c = va_arg(ap, int);
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    &c, sizeof(c));
			break;
		case 'h':
			h = va_arg(ap, int);
			h = htons(h);
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    &h, sizeof(h));
			break;
		case 'i':
			i = va_arg(ap, gfarm_int32_t);
			i = htonl(i);
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    &i, sizeof(i));
			break;
		case 'o':
			/*
			 * note that because actual type of file_offset_t
			 * may be diffenent (int64_t or double), we must
			 * not pass this as is via network.
			 */
			o = va_arg(ap, file_offset_t);
#if FILE_OFFSET_T_IS_FLOAT
			minus = o < 0;
			if (minus)
				o = -o;
			ov[0] = o / POWER2_32;
			ov[1] = o - ov[0] * POWER2_32;
			if (minus) {
				ov[0] = ~ov[0];
				ov[1] = ~ov[1];
				if (++ov[1] == 0)
					++ov[0];
			}
#else
			ov[0] = o >> 32;
			ov[1] = o;
#endif
			ov[0] = htonl(ov[0]);
			ov[1] = htonl(ov[1]);
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    ov, sizeof(ov));
			break;
		case 's':
			s = va_arg(ap, char *);
			n = strlen(s);
			i = htonl(n);
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    &i, sizeof(i));
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    s, n);
			break;
		case 'b':
			/*
			 * note that because actual type of size_t may be
			 * diffenent ([u]int32_t or [u]int64_t), we must not
			 * pass this as is via network.
			 */
			n = va_arg(ap, size_t);
			i = htonl(n);
			s = va_arg(ap, char *);
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    &i, sizeof(i));
			gfarm_iobuffer_put_write(conn->sendbuffer,
			    s, n);
			break;
		default:
			goto finish;
		}
	}
 finish:
	*formatp = format;
	va_copy(*app, ap);
	return (gfarm_iobuffer_get_error(conn->sendbuffer));
}
Exemplo n.º 4
0
char *
xxx_proto_vrecv(struct xxx_connection *conn, int just, int *eofp,
	char **formatp, va_list *app)
{
	char *format = *formatp;
	va_list ap;
	gfarm_int8_t *cp;
	gfarm_int16_t *hp;
	gfarm_int32_t *ip, i;
	file_offset_t *op;
	gfarm_uint32_t ov[2];
#if FILE_OFFSET_T_IS_FLOAT
	int minus;
#endif
	char **sp, *s;
	size_t *szp, sz;
	char *e;

	va_copy(ap, *app);
	e = xxx_proto_flush(conn);
	if (e != NULL)
		return (e);

	*eofp = 1;

	for (; *format; format++) {
		switch (*format) {
		case 'c':
			cp = va_arg(ap, gfarm_int8_t *);
			if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
			    cp, sizeof(*cp), just) != sizeof(*cp))
				return (NULL);
			break;
		case 'h':
			hp = va_arg(ap, gfarm_int16_t *);
			if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
			    hp, sizeof(*hp), just) != sizeof(*hp))
				return (NULL);
			*hp = ntohs(*hp);
			break;
		case 'i':
			ip = va_arg(ap, gfarm_int32_t *);
			if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
			    ip, sizeof(*ip), just) != sizeof(*ip))
				return (NULL);
			*ip = ntohl(*ip);
			break;
		case 'o':
			/*
			 * note that because actual type of file_offset_t
			 * may be diffenent (int64_t or double), we must
			 * not pass this as is via network.
			 */
			op = va_arg(ap, file_offset_t *);
			if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
			    ov, sizeof(ov), just) != sizeof(ov))
				return (NULL);
			ov[0] = ntohl(ov[0]);
			ov[1] = ntohl(ov[1]);
#if FILE_OFFSET_T_IS_FLOAT
			minus = ov[0] & 0x80000000;
			if (minus) {
				ov[0] = ~ov[0];
				ov[1] = ~ov[1];
				if (++ov[1] == 0)
					++ov[0];
			}
			*op = ov[0] * POWER2_32 + ov[1];
			if (minus)
				*op = -*op;
#else
			*op = ((file_offset_t)ov[0] << 32) | ov[1];
#endif
			break;
		case 's':
			sp = va_arg(ap, char **);
			if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
			    &i, sizeof(i), just) != sizeof(i))
				return (NULL);
			i = ntohl(i);
			*sp = malloc(i + 1);
			if (*sp != NULL) {
				/* caller should check whether *sp == NULL */
				if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
				    *sp, i, just) != i)
					return (NULL);
				(*sp)[i] = '\0';
			}
			break;
		case 'b':
			/*
			 * note that because actual type of size_t may be
			 * diffenent ([u]int32_t or [u]int64_t), we must not
			 * pass this as is via network.
			 */
			sz = va_arg(ap, size_t);
			szp = va_arg(ap, size_t *);
			s = va_arg(ap, char *);
			if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
			    &i, sizeof(i), just) != sizeof(i))
				return (NULL);
			i = ntohl(i);
			*szp = i;
			if (i <= sz) {
				if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
				    s, i, just) != i)
					return (NULL);
			} else {
				if (gfarm_iobuffer_get_read_x(conn->recvbuffer,
				    s, sz, just) != sz)
					return (NULL);
				/* abandon (i - sz) bytes */
				if (gfarm_iobuffer_purge_read_x(
				    conn->recvbuffer, i - sz, just) != i - sz)
					return (NULL);
			}
			break;
		default:
			goto finish;
		}
	}
 finish:
	*formatp = format;
	va_copy(*app, ap);
	*eofp = 0;
	return (gfarm_iobuffer_get_error(conn->recvbuffer));
}
Exemplo n.º 5
0
char *
xxx_proto_flush(struct xxx_connection *conn)
{
	gfarm_iobuffer_flush_write(conn->sendbuffer);
	return (gfarm_iobuffer_get_error(conn->sendbuffer));
}