-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(VsockFirecrackerClient): Add client to talk to FC microVMs
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getLogger } from '@stencila/logga'; | ||
import net from 'net'; | ||
import { VsockAddress } from '../base/Transports'; | ||
import StreamClient from '../stream/StreamClient'; | ||
|
||
const log = getLogger('executa:vsock:client') | ||
|
||
export default class VsockFirecrackerClient extends StreamClient { | ||
private socket: net.Socket | ||
|
||
public constructor(address: VsockAddress = new VsockAddress()) { | ||
const { path, port} = address | ||
if (path === undefined) throw (`Path is required`) | ||
|
||
const socket = net.connect(path) | ||
socket.on('connect', () => { | ||
log.debug(`${path}:${port}: connecting`) | ||
socket.write(`CONNECT ${port}\n`) | ||
}) | ||
socket.on('error', error => { | ||
log.error(`${path}:${port}: ${error}`) | ||
}) | ||
socket.on('close', () => { | ||
// If there is no server listening in the VM then the connection will be closed. | ||
log.debug(`${path}:${port}: connection-closed`) | ||
}) | ||
|
||
super(socket, socket) | ||
this.socket = socket | ||
} | ||
|
||
public stop() { | ||
this.socket.destroy() | ||
} | ||
} |