static int _send_resp(slurm_fd_t fd, Buf buffer) { uint32_t msg_size, nw_size; ssize_t msg_wrote; char *out_buf; if ((fd < 0) || (!fd_writeable(fd))) goto io_err; msg_size = get_buf_offset(buffer); nw_size = htonl(msg_size); if (!fd_writeable(fd)) goto io_err; msg_wrote = write(fd, &nw_size, sizeof(nw_size)); if (msg_wrote != sizeof(nw_size)) goto io_err; out_buf = get_buf_data(buffer); while (msg_size > 0) { if (!fd_writeable(fd)) goto io_err; msg_wrote = write(fd, out_buf, msg_size); if (msg_wrote <= 0) goto io_err; out_buf += msg_wrote; msg_size -= msg_wrote; } free_buf(buffer); return SLURM_SUCCESS; io_err: free_buf(buffer); return SLURM_ERROR; }
static int trans_data_pty2sock() { char buf[256]; int ret; if (pty2sock_cache_len>0) goto DO_SEND_DATA; cur_snd_ptr = pty2sock_cache; pty2sock_cache_len = 0; ret=read_reliable(fd_pty_master, buf, sizeof(buf)); if (ret<0) { return ret; } buf[ret]=0; //printf_to_fd(ori_std_output, "== ret=%d\n", ret); ret=str_replace_substr(pty2sock_cache, buf, "\n", "\r\n"); //printf_to_fd(ori_std_output, "77 ret=%d\n", ret); cur_snd_ptr = pty2sock_cache; pty2sock_cache_len = ret; if (ret==0) return 0; DO_SEND_DATA: if (!fd_writeable(fd_conn, 0, 0)) { return 0; } ret=write_reliable(fd_conn, pty2sock_cache, pty2sock_cache_len); //printf_to_fd(ori_std_output, "write ret=%d\n", ret); if (ret<0) { //printf_to_fd(ori_std_output, "%s", strerror(errno)); return ret; } if (ret==0) { return -1; } pty2sock_cache_len -= ret; cur_snd_ptr+=ret; return 0; }