MCPcopy
hub / github.com/plasma-umass/browsix / SocketFile

Class SocketFile

src/kernel/socket.ts:28–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28export class SocketFile implements IFile {
29 task: ITask;
30 isListening: boolean = false;
31 parent: SocketFile = undefined;
32 refCount: number = 1;
33
34 port: number;
35 addr: string;
36
37 peer: SocketFile = undefined;
38
39 outgoing: Pipe = undefined;
40 incoming: Pipe = undefined;
41
42 incomingQueue: Incoming[] = [];
43 acceptQueue: AcceptCallback[] = [];
44
45 constructor(task: ITask) {
46 this.task = task;
47 }
48
49 stat(cb: (err: any, stats: any) => void): void {
50 throw new Error('TODO: SocketFile.stat not implemented');
51 }
52
53 readdir(cb: (err: any, files: string[]) => void): void {
54 setTimeout(cb, 0, 'cant readdir on normal file');
55 }
56
57 listen(cb: (err: number) => void): void {
58 this.isListening = true;
59 cb(0);
60 }
61
62 accept(cb: AcceptCallback): void {
63 if (!this.incomingQueue.length) {
64 this.acceptQueue.push(cb);
65 return;
66 }
67
68 let queued = this.incomingQueue.shift();
69
70 let remote = queued.s;
71 let local = new SocketFile(this.task);
72 local.addr = queued.addr;
73 local.port = queued.port;
74
75 let outgoing = new Pipe();
76 let incoming = new Pipe();
77
78 local.outgoing = outgoing;
79 remote.incoming = outgoing;
80
81 local.incoming = incoming;
82 remote.outgoing = incoming;
83
84 local.peer = remote;
85 remote.peer = local;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected