/* * 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); }
static int gfarm_iobuffer_read_session_x(struct gfarm_iobuffer *b, void *cookie, int fd, void *data, int length, int do_timeout) { struct io_gfsl *io = cookie; int rv; int msec = do_timeout ? gfarm_ctxp->network_receive_timeout * 1000 : GFARM_GSS_TIMEOUT_INFINITE; if (io->buffer == NULL) { int flag = fcntl(fd, F_GETFL, NULL); /* temporary drop O_NONBLOCK flag to prevent EAGAIN */ if (flag & O_NONBLOCK) fcntl(fd, F_SETFL, flag & ~O_NONBLOCK); rv = gfarmSecSessionReceiveInt8(io->session, &io->buffer, &io->residual, msec); if (flag & O_NONBLOCK) fcntl(fd, F_SETFL, flag); if (rv <= 0) { /* XXX - interpret io->session->gssLastStat */ /* XXX - set GFARM_ERR_BROKEN_PIPE to reconnect */ gfarm_iobuffer_set_error(b, GFARM_ERR_BROKEN_PIPE); return (rv); } io->p = 0; } if (io->residual <= length) { rv = io->residual; memcpy(data, &io->buffer[io->p], rv); free(io->buffer); io->buffer = NULL; io->p = io->residual = 0; } else { rv = length; memcpy(data, &io->buffer[io->p], rv); io->p += rv; io->residual -= rv; } return (rv); }
int gfarm_iobuffer_read_secsession_op(struct gfarm_iobuffer *b, void *cookie, int fd, void *data, int length) { struct io_gfsl *io = cookie; int rv; if (io->buffer == NULL) { int flag = fcntl(fd, F_GETFL, NULL); /* temporary drop O_NONBLOCK flag to prevent EAGAIN */ if (flag & O_NONBLOCK) fcntl(fd, F_SETFL, flag & ~O_NONBLOCK); rv = gfarmSecSessionReceiveInt8(io->session, &io->buffer, &io->residual); if (flag & O_NONBLOCK) fcntl(fd, F_SETFL, flag); if (rv <= 0) { /* XXX - interpret io->session->gssLastStat */ gfarm_iobuffer_set_error(b, GFARM_ERR_UNKNOWN); return (rv); } io->p = 0; } if (io->residual <= length) { rv = io->residual; memcpy(data, &io->buffer[io->p], rv); free(io->buffer); io->buffer = NULL; io->p = io->residual = 0; } else { rv = length; memcpy(data, &io->buffer[io->p], rv); io->p += rv; io->residual -= rv; } return (rv); }
int gfarm_iobuffer_write_secsession_op(struct gfarm_iobuffer *b, void *cookie, int fd, void *data, int length) { struct io_gfsl *io = cookie; int rv, flag = fcntl(fd, F_GETFL, NULL); /* temporary drop O_NONBLOCK flag to prevent EAGAIN */ if (flag & O_NONBLOCK) fcntl(fd, F_SETFL, flag & ~O_NONBLOCK); rv = gfarmSecSessionSendInt8(io->session, data, length); if (flag & O_NONBLOCK) fcntl(fd, F_SETFL, flag); if (rv <= 0) { /* XXX - interpret io->session->gssLastStat */ gfarm_iobuffer_set_error(b, GFARM_ERR_UNKNOWN); } return (rv); }