File: Session.cpp

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (110 lines) | stat: -rw-r--r-- 1,839 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
110
#include "stdafx.h"
#include "Session.h"

#include "SecureChannel.h"
#include "OpenSSL.h"

namespace ssl {

	// TODO: Platform independence...

	Session::Session(IStream *input, OStream *output, SSLSession *ctx, Str *host) : data(ctx), gcData(null) {
		gcData = data->connect(input, output, host);
	}

	Session::Session(const Session &o) : data(o.data), gcData(o.gcData) {
		data->ref();
	}

	Session::~Session() {
		data->unref();
	}

	void Session::deepCopy(CloneEnv *) {
		// No need.
	}

	IStream *Session::input() {
		return new (this) SessionIStream(this);
	}

	OStream *Session::output() {
		return new (this) SessionOStream(this);
	}

	void Session::close() {
		shutdown();
		data->close(gcData);
	}

	Bool Session::more() {
		return data->more(gcData);
	}

	void Session::read(Buffer &to) {
		if (to.free() > 0)
			data->read(to, gcData);
	}

	void Session::peek(Buffer &to) {
		data->peek(to, gcData);
	}

	Nat Session::write(const Buffer &from, Nat offset) {
		if (offset >= from.filled())
			return 0;

		return data->write(from, offset, gcData);
	}

	Bool Session::flush() {
		return data->flush(gcData);
	}

	void Session::shutdown() {
		data->shutdown(gcData);
	}


	/**
	 * Input stream.
	 */

	SessionIStream::SessionIStream(Session *owner) : owner(owner) {}

	void SessionIStream::close() {}

	Bool SessionIStream::more() {
		return owner->more();
	}

	Buffer SessionIStream::read(Buffer to) {
		owner->read(to);
		return to;
	}

	Buffer SessionIStream::peek(Buffer to) {
		owner->peek(to);
		return to;
	}


	/**
	 * Output stream.
	 */

	SessionOStream::SessionOStream(Session *owner) : owner(owner) {}

	void SessionOStream::close() {
		owner->shutdown();
	}

	Nat SessionOStream::write(Buffer from, Nat offset) {
		return owner->write(from, offset);
	}

	Bool SessionOStream::flush() {
		return owner->flush();
	}

}