xref: /unit/src/nodejs/unit-http/socket.js (revision 1132:9ac5b5f33ed9)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6'use strict';
7
8const EventEmitter = require('events');
9const util = require('util');
10const unit_lib = require('./build/Release/unit-http');
11
12function Socket(options) {
13    EventEmitter.call(this);
14
15    options = options || {};
16
17    if (typeof options !== 'object') {
18        throw new TypeError('Options must be object');
19    }
20
21    if ("fd" in options) {
22        throw new TypeError('Working with file descriptors not supported');
23    }
24
25    /*
26     * For HTTP TCP socket 'readable' and 'writable' are always true.
27     * These options are required by Express and Koa frameworks.
28     */
29    this.readable = true;
30    this.writable = true;
31}
32util.inherits(Socket, EventEmitter);
33
34Socket.prototype.bufferSize = 0;
35Socket.prototype.bytesRead = 0;
36Socket.prototype.bytesWritten = 0;
37Socket.prototype.connecting = false;
38Socket.prototype.destroyed = false;
39Socket.prototype.localAddress = "";
40Socket.prototype.localPort = 0;
41Socket.prototype.remoteAddress = "";
42Socket.prototype.remoteFamily = "";
43Socket.prototype.remotePort = 0;
44
45Socket.prototype.address = function address() {
46};
47
48Socket.prototype.connect = function connect(options, connectListener) {
49    this.once('connect', connectListener);
50
51    this.connecting = true;
52
53    return this;
54};
55
56Socket.prototype.destroy = function destroy(exception) {
57    this.connecting = false;
58    this.readable = false;
59    this.writable = false;
60
61    return this;
62};
63
64Socket.prototype.end = function end(data, encoding, callback) {
65};
66
67Socket.prototype.pause = function pause() {
68};
69
70Socket.prototype.ref = function ref() {
71};
72
73Socket.prototype.resume = function resume() {
74};
75
76Socket.prototype.setEncoding = function setEncoding(encoding) {
77};
78
79Socket.prototype.setKeepAlive = function setKeepAlive(enable, initialDelay) {
80};
81
82Socket.prototype.setNoDelay = function setNoDelay(noDelay) {
83};
84
85Socket.prototype.setTimeout = function setTimeout(timeout, callback) {
86    if (typeof timeout !== 'number') {
87        throw new TypeError('Timeout must be number');
88    }
89
90    this.timeout = timeout;
91
92    // this.on('timeout', callback);
93
94    return this;
95};
96
97Socket.prototype.unref = function unref() {
98};
99
100Socket.prototype.write = function write(data, encoding, callback) {
101};
102
103
104module.exports = Socket;
105