-
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.
Co-authored-by: Kasper Isager Dalsgarð <[email protected]>
- Loading branch information
1 parent
7b44dc0
commit 973972b
Showing
2 changed files
with
99 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import EventEmitter from 'bare-events' | ||
import Buffer from 'bare-buffer' | ||
|
||
export interface RemoteInfo { | ||
address: string | ||
family: 'IPv4' | 'IPv6' | ||
port: number | ||
size: number | ||
} | ||
|
||
export class Socket extends EventEmitter<{ | ||
close: [] | ||
connect: [] | ||
error: [err: Error] | ||
listening: [] | ||
message: [message: string | Buffer, remote: RemoteInfo] | ||
}> { | ||
constructor(opts?: { ipv6Only?: boolean; reuseAddress?: boolean }) | ||
|
||
address(): { address: string; family: string; port: number } | null | ||
|
||
remoteAddress(): { address: string; family: string; port: number } | null | ||
|
||
bind(port: number, address: string, cb?: () => void): this | ||
bind(opts: { port?: number; address?: string }, cb?: () => void): this | ||
bind(port: number, cb?: () => void): this | ||
bind(cb?: () => void): this | ||
|
||
connect(port: number, address: string, cb?: () => void): void | ||
connect(port: number, cb?: () => void): void | ||
|
||
close(cb?: (err: Error) => void): Promise<void> | ||
|
||
send( | ||
msg: string | Buffer, | ||
offset: number, | ||
length: number, | ||
port?: number, | ||
address?: string, | ||
cb?: (err: Error) => void | ||
): Promise<void> | ||
|
||
send( | ||
msg: string | Buffer, | ||
offset: number, | ||
length: number, | ||
port: number, | ||
cb: (err: Error) => void | ||
): Promise<void> | ||
|
||
send( | ||
msg: string | Buffer, | ||
offset: number, | ||
length: number, | ||
address: string, | ||
cb: (err: Error) => void | ||
): Promise<void> | ||
|
||
send( | ||
msg: string | Buffer, | ||
offset: number, | ||
address: string, | ||
cb: (err: Error) => void | ||
): Promise<void> | ||
|
||
send( | ||
msg: string | Buffer, | ||
offset: number, | ||
length: number, | ||
cb: (err: Error) => void | ||
): Promise<void> | ||
|
||
send(msg: string | Buffer, port: number, address: string): Promise<void> | ||
|
||
send( | ||
msg: string | Buffer, | ||
port: number, | ||
cb?: (err: Error) => void | ||
): Promise<void> | ||
|
||
send(msg: string | Buffer, address: string): Promise<void> | ||
|
||
send(msg: string | Buffer, cb: (err: Error) => void): Promise<void> | ||
} | ||
|
||
export function createSocket( | ||
opts?: { ipv6Only?: boolean; reuseAddress?: boolean } | string, | ||
cb?: (message: Buffer, remote: RemoteInfo) => void | ||
): Socket |
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