File: localportsession.cc

package info (click to toggle)
latd 1.30
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,352 kB
  • ctags: 1,046
  • sloc: cpp: 8,489; sh: 878; makefile: 85
file content (99 lines) | stat: -rw-r--r-- 2,672 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/******************************************************************************
    (c) 2001-2003 Christine Caulfield                 christine.caulfield@googlemail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
******************************************************************************/

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#include <string.h>
#include <stdio.h>
#include <syslog.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <list>
#include <queue>
#include <string>
#include <map>
#include <sstream>

#include "lat.h"
#include "utils.h"
#include "session.h"
#include "localport.h"
#include "connection.h"
#include "circuit.h"
#include "latcpcircuit.h"
#include "server.h"
#include "clientsession.h"
#include "lloginsession.h"
#include "localportsession.h"
#include "lat_messages.h"

localportSession::localportSession(class LATConnection &p, LocalPort *port,
				   unsigned char remid, unsigned char localid,
				   char *lta, int fd):
    lloginSession(p, remid, localid, lta, clean),
    localport(port),
    minimum_read(0),
    ignored_read(false)
{
    master_fd = fd;

    debuglog(("new localport session: localid %d, remote id %d, fd=%d\n",
	      localid, remid, fd));

    state = STARTING;
}


localportSession::~localportSession()
{
    close (master_fd);

    // Invalidate the FD number so it doesn't get closed when
    // the superclass destructors get called.
    LATServer::Instance()->remove_fd(master_fd);
    master_fd = -1;

    // Restart PTY so it can accept new connections
    debuglog(("Restarting PTY for local session\n"));
    localport->restart_pty();
}

void localportSession::do_read()
{
    // If there are less than "minimum_read" bytes available then
    // wait until the next time around. We never leave it for more
    // than one timer tick though.
    int numbytes;
    ioctl(master_fd, FIONREAD, &numbytes);
    if (numbytes < minimum_read && !ignored_read)
    {
	ignored_read = true;
    }
    else
    {
	read_pty();
	ignored_read = false;
    }
}

void localportSession::show_status(unsigned char *node, LAT_StatusEntry *entry)
{
    // Dont show status.
}