Bubbled up reusePort to the API as an option on createSocket
This commit is contained in:
parent
6f62be0d6e
commit
822b1e0933
|
@ -43,6 +43,7 @@ function UdpSocket(options, onmessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.type = options.type
|
this.type = options.type
|
||||||
|
this.reusePort = options && options.reusePort
|
||||||
this._ipv = Number(this.type.slice(3))
|
this._ipv = Number(this.type.slice(3))
|
||||||
this._ipRegex = ipRegex['v' + this._ipv]({ exact: true })
|
this._ipRegex = ipRegex['v' + this._ipv]({ exact: true })
|
||||||
this._id = instances++
|
this._id = instances++
|
||||||
|
@ -89,7 +90,7 @@ UdpSocket.prototype.bind = function(port, address, callback) {
|
||||||
|
|
||||||
this._state = STATE.BINDING
|
this._state = STATE.BINDING
|
||||||
this._debug('binding, address:', address, 'port:', port)
|
this._debug('binding, address:', address, 'port:', port)
|
||||||
Sockets.bind(this._id, port, address, function(err, addr) {
|
Sockets.bind(this._id, port, address, {reusePort: this.reusePort }, function(err, addr) {
|
||||||
err = normalizeError(err)
|
err = normalizeError(err)
|
||||||
if (err) {
|
if (err) {
|
||||||
// questionable: may want to self-destruct and
|
// questionable: may want to self-destruct and
|
||||||
|
|
|
@ -61,9 +61,10 @@ typedef enum RCTUDPError RCTUDPError;
|
||||||
*
|
*
|
||||||
* @param port
|
* @param port
|
||||||
* @param host ip address
|
* @param host ip address
|
||||||
|
* @param options (such as 'reusePort')
|
||||||
* @return true if bound, false if there was an error
|
* @return true if bound, false if there was an error
|
||||||
*/
|
*/
|
||||||
- (BOOL)bind:(u_int16_t) port address:(NSString*) address error:(NSError**)error;
|
- (BOOL)bind:(u_int16_t) port address:(NSString*)address options:(NSDictionary *)options error:(NSError**)error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join multicast groupt
|
* Join multicast groupt
|
||||||
|
|
|
@ -78,7 +78,7 @@ NSString *const RCTUDPErrorDomain = @"RCTUDPErrorDomain";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) bind:(u_int16_t)port address:(NSString *)address error:(NSError **) error
|
- (BOOL)bind:(u_int16_t)port address:(NSString *)address options:(NSDictionary *)options error:(NSError **) error
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_port) {
|
if (_port) {
|
||||||
|
@ -96,7 +96,9 @@ NSString *const RCTUDPErrorDomain = @"RCTUDPErrorDomain";
|
||||||
|
|
||||||
[_udpSocket setMaxReceiveIPv4BufferSize:UINT16_MAX];
|
[_udpSocket setMaxReceiveIPv4BufferSize:UINT16_MAX];
|
||||||
[_udpSocket setMaxReceiveIPv6BufferSize:UINT16_MAX];
|
[_udpSocket setMaxReceiveIPv6BufferSize:UINT16_MAX];
|
||||||
[_udpSocket enableReusePort:true error:error];
|
|
||||||
|
BOOL reusePort = options[@"reusePort"] ?: NO;
|
||||||
|
[_udpSocket enableReusePort:reusePort error:error];
|
||||||
|
|
||||||
BOOL result;
|
BOOL result;
|
||||||
if (address) {
|
if (address) {
|
||||||
|
|
|
@ -53,13 +53,14 @@ RCT_EXPORT_METHOD(createSocket:(nonnull NSNumber*)cId withOptions:(NSDictionary*
|
||||||
RCT_EXPORT_METHOD(bind:(nonnull NSNumber*)cId
|
RCT_EXPORT_METHOD(bind:(nonnull NSNumber*)cId
|
||||||
port:(int)port
|
port:(int)port
|
||||||
address:(NSString *)address
|
address:(NSString *)address
|
||||||
|
options:(NSDictionary *)options
|
||||||
callback:(RCTResponseSenderBlock)callback)
|
callback:(RCTResponseSenderBlock)callback)
|
||||||
{
|
{
|
||||||
UdpSocketClient* client = [self findClient:cId callback:callback];
|
UdpSocketClient* client = [self findClient:cId callback:callback];
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
|
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
if (![client bind:port address:address error:&error])
|
if (![client bind:port address:address options:options error:&error])
|
||||||
{
|
{
|
||||||
NSString *msg = error.localizedFailureReason ?: error.localizedDescription;
|
NSString *msg = error.localizedFailureReason ?: error.localizedDescription;
|
||||||
callback(@[msg ?: @"unknown error when binding"]);
|
callback(@[msg ?: @"unknown error when binding"]);
|
||||||
|
|
Loading…
Reference in New Issue