Lines Matching refs:tm
175 static int handle_iacs(struct term_session *tm, int c, int fd)
180 curr = start = tm->buff2+tm->buff2_avail;
181 end = tm->buff2 + c -1;
182 tm->rem = 0;
199 tm->rem = 1;
216 tm->rem = end - curr;
225 curr++, tm->rem++;
228 tm->rem++;
231 tm->rem = 0;
239 memcpy(start + i, end - tm->rem, tm->rem); //put remaining if we break;
273 struct term_session *tm = NULL;
288 tm = xzalloc(sizeof(struct term_session));
289 tm->child_pid = TT.fork_pid;
290 tm->new_fd = 0;
291 tm->pty_fd = pty_fd;
293 tm->next = session_list;
294 session_list = tm;
295 } else session_list = tm;
310 tm = session_list;
311 while (tm) {
313 if (tm->pty_fd > 0 && tm->buff1_avail < BUFSIZE) FD_SET(tm->pty_fd, &rd);
314 if (tm->new_fd >= 0 && tm->buff2_avail < BUFSIZE) FD_SET(tm->new_fd, &rd);
315 if (tm->pty_fd > 0 && (tm->buff2_avail - tm->buff2_written) > 0)
316 FD_SET(tm->pty_fd, &wr);
317 if (tm->new_fd >= 0 && (tm->buff1_avail - tm->buff1_written) > 0)
318 FD_SET(tm->new_fd, &wr);
319 tm = tm->next;
336 tm = xzalloc(sizeof(struct term_session));
337 tm->child_pid = TT.fork_pid;
338 tm->new_fd = new_fd;
339 tm->pty_fd = pty_fd;
341 tm->next = session_list;
342 session_list = tm;
343 } else session_list = tm;
346 tm = session_list;
347 for (;tm;tm=tm->next) {
348 if (FD_ISSET(tm->pty_fd, &rd)) {
349 if ((c = read(tm->pty_fd, tm->buff1 + tm->buff1_avail,
350 BUFSIZE-tm->buff1_avail)) <= 0) break;
351 tm->buff1_avail += c;
352 if ((w = dup_iacs(tm->buff1 + tm->buff1_written, tm->new_fd + FLAG(i),
353 tm->buff1_avail - tm->buff1_written)) < 0) break;
354 tm->buff1_written += w;
356 if (FD_ISSET(tm->new_fd, &rd)) {
357 if ((c = read(tm->new_fd, tm->buff2+tm->buff2_avail,
358 BUFSIZE-tm->buff2_avail)) <= 0) {
361 xclose(tm->new_fd);
362 tm->new_fd = -1;
363 xclose(tm->pty_fd);
364 tm->pty_fd = -1;
367 c = handle_iacs(tm, c, tm->pty_fd);
368 tm->buff2_avail += c;
369 if ((w = write(tm->pty_fd, tm->buff2+ tm->buff2_written,
370 tm->buff2_avail - tm->buff2_written)) < 0) break;
371 tm->buff2_written += w;
373 if (FD_ISSET(tm->pty_fd, &wr)) {
374 if ((w = write(tm->pty_fd, tm->buff2 + tm->buff2_written,
375 tm->buff2_avail - tm->buff2_written)) < 0) break;
376 tm->buff2_written += w;
378 if (FD_ISSET(tm->new_fd, &wr)) {
379 if ((w = dup_iacs(tm->buff1 + tm->buff1_written, tm->new_fd + FLAG(i),
380 tm->buff1_avail - tm->buff1_written)) < 0) break;
381 tm->buff1_written += w;
383 if (tm->buff1_written == tm->buff1_avail)
384 tm->buff1_written = tm->buff1_avail = 0;
385 if (tm->buff2_written == tm->buff2_avail)
386 tm->buff2_written = tm->buff2_avail = 0;
402 for (tm = session_list; tm; tm = tm->next) {
403 if (tm->child_pid == pid) break;
404 prev = tm;
406 if (!tm) error_exit("unexpected reparenting of %d", pid);
411 else prev->next = tm->next;
412 xclose(tm->pty_fd);
413 xclose(tm->new_fd);
414 free(tm);