Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#2480 from rogierschouten/nodedgram
Browse files Browse the repository at this point in the history
Improve Node dgram signatures.
  • Loading branch information
basarat committed Jul 8, 2014
2 parents e35336d + b5acb56 commit d20e745
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 14 additions & 1 deletion node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import util = require("util");
import crypto = require("crypto");
import http = require("http");
import net = require("net");
import dgram = require("dgram");

assert(1 + 1 - 2 === 0, "The universe isn't how it should.");

Expand Down Expand Up @@ -109,4 +110,16 @@ module http_tests {
var code = 100;
var codeMessage = http.STATUS_CODES['400'];
var codeMessage = http.STATUS_CODES[400];
}
}

////////////////////////////////////////////////////
/// Dgram tests : http://nodejs.org/api/dgram.html
////////////////////////////////////////////////////

var ds: dgram.Socket = dgram.createSocket("udp4", (msg: Buffer, rinfo: dgram.RemoteInfo): void => {
});
var ai: dgram.AddressInfo = ds.address();
ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error, bytes: number): void => {
});


16 changes: 14 additions & 2 deletions node/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,13 +760,25 @@ declare module "net" {
declare module "dgram" {
import events = require("events");

export function createSocket(type: string, callback?: Function): Socket;
interface RemoteInfo {
address: string;
port: number;
size: number;
}

interface AddressInfo {
address: string;
family: string;
port: number;
}

export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;

interface Socket extends events.EventEmitter {
send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void;
bind(port: number, address?: string, callback?: () => void): void;
close(): void;
address: { address: string; family: string; port: number; };
address(): AddressInfo;
setBroadcast(flag: boolean): void;
setMulticastTTL(ttl: number): void;
setMulticastLoopback(flag: boolean): void;
Expand Down

0 comments on commit d20e745

Please sign in to comment.