@@ -332,12 +332,13 @@ namespace ix
332
332
}
333
333
334
334
// Retrieve connection info, the ip address of the remote peer/client)
335
- std::unique_ptr<ConnectionInfo> connectionInfo;
335
+ std::string remoteIp;
336
+ int remotePort;
336
337
337
338
if (_addressFamily == AF_INET)
338
339
{
339
- char remoteIp [INET_ADDRSTRLEN];
340
- if (inet_ntop (AF_INET, &client.sin_addr , remoteIp , INET_ADDRSTRLEN) == nullptr )
340
+ char remoteIp4 [INET_ADDRSTRLEN];
341
+ if (inet_ntop (AF_INET, &client.sin_addr , remoteIp4 , INET_ADDRSTRLEN) == nullptr )
341
342
{
342
343
int err = Socket::getErrno ();
343
344
std::stringstream ss;
@@ -350,12 +351,13 @@ namespace ix
350
351
continue ;
351
352
}
352
353
353
- connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port );
354
+ remotePort = client.sin_port ;
355
+ remoteIp = remoteIp4;
354
356
}
355
357
else // AF_INET6
356
358
{
357
- char remoteIp [INET6_ADDRSTRLEN];
358
- if (inet_ntop (AF_INET6, &client.sin_addr , remoteIp , INET6_ADDRSTRLEN) == nullptr )
359
+ char remoteIp6 [INET6_ADDRSTRLEN];
360
+ if (inet_ntop (AF_INET6, &client.sin_addr , remoteIp6 , INET6_ADDRSTRLEN) == nullptr )
359
361
{
360
362
int err = Socket::getErrno ();
361
363
std::stringstream ss;
@@ -368,7 +370,8 @@ namespace ix
368
370
continue ;
369
371
}
370
372
371
- connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port );
373
+ remotePort = client.sin_port ;
374
+ remoteIp = remoteIp6;
372
375
}
373
376
374
377
std::shared_ptr<ConnectionState> connectionState;
@@ -377,6 +380,8 @@ namespace ix
377
380
connectionState = _connectionStateFactory ();
378
381
}
379
382
connectionState->setOnSetTerminatedCallback ([this ] { onSetTerminatedCallback (); });
383
+ connectionState->setRemoteIp (remoteIp);
384
+ connectionState->setRemotePort (remotePort);
380
385
381
386
if (_stop) return ;
382
387
@@ -404,13 +409,10 @@ namespace ix
404
409
405
410
// Launch the handleConnection work asynchronously in its own thread.
406
411
std::lock_guard<std::mutex> lock (_connectionsThreadsMutex);
407
- _connectionsThreads.push_back (
408
- std::make_pair (connectionState,
409
- std::thread (&SocketServer::handleConnection,
410
- this ,
411
- std::move (socket),
412
- connectionState,
413
- std::move (connectionInfo))));
412
+ _connectionsThreads.push_back (std::make_pair (
413
+ connectionState,
414
+ std::thread (
415
+ &SocketServer::handleConnection, this , std::move (socket), connectionState)));
414
416
}
415
417
}
416
418
0 commit comments