@@ -1545,19 +1545,20 @@ PHP_FUNCTION(swoole_connection_info)
1545
1545
{
1546
1546
zval * zobject = getThis ();
1547
1547
swServer * serv ;
1548
+ zend_bool noCheckConnection = 0 ;
1548
1549
long fd = 0 ;
1549
1550
long from_id = -1 ;
1550
1551
1551
1552
if (zobject == NULL )
1552
1553
{
1553
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "Ol|l " , & zobject , swoole_server_class_entry_ptr , & fd , & from_id ) == FAILURE )
1554
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "Ol|lb " , & zobject , swoole_server_class_entry_ptr , & fd , & from_id , & noCheckConnection ) == FAILURE )
1554
1555
{
1555
1556
return ;
1556
1557
}
1557
1558
}
1558
1559
else
1559
1560
{
1560
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "l|l " , & fd , & from_id ) == FAILURE )
1561
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "l|lb " , & fd , & from_id , & noCheckConnection ) == FAILURE )
1561
1562
{
1562
1563
return ;
1563
1564
}
@@ -1566,49 +1567,49 @@ PHP_FUNCTION(swoole_connection_info)
1566
1567
1567
1568
swConnection * conn = swServer_connection_get (serv , fd );
1568
1569
1569
- //It's udp
1570
- if (conn == NULL )
1571
- {
1572
- array_init (return_value );
1573
- php_swoole_udp_t udp_info ;
1574
- if (from_id < 0 )
1575
- {
1576
- from_id = php_swoole_udp_from_id ;
1577
- }
1578
- memcpy (& udp_info , & from_id , sizeof (udp_info ));
1570
+ //udp client
1571
+ if (conn == NULL )
1572
+ {
1573
+ array_init (return_value );
1574
+ php_swoole_udp_t udp_info ;
1575
+ if (from_id < 0 )
1576
+ {
1577
+ from_id = php_swoole_udp_from_id ;
1578
+ }
1579
+ memcpy (& udp_info , & from_id , sizeof (udp_info ));
1579
1580
1580
- swConnection * from_sock = swServer_connection_get (serv , udp_info .from_fd );
1581
- struct in_addr sin_addr ;
1582
- sin_addr .s_addr = fd ;
1583
- if (from_sock != NULL )
1584
- {
1585
- add_assoc_long (return_value , "from_fd" , udp_info .from_fd );
1586
- add_assoc_long (return_value , "from_port" , from_sock -> addr .sin_port );
1587
- }
1588
- if (from_id != 0 )
1589
- {
1590
- add_assoc_long (return_value , "remote_port" , udp_info .port );
1591
- }
1592
- add_assoc_string (return_value , "remote_ip" , inet_ntoa (sin_addr ), 1 );
1593
- return ;
1594
- }
1581
+ swConnection * from_sock = swServer_connection_get (serv , udp_info .from_fd );
1582
+ struct in_addr sin_addr ;
1583
+ sin_addr .s_addr = fd ;
1584
+ if (from_sock != NULL )
1585
+ {
1586
+ add_assoc_long (return_value , "from_fd" , udp_info .from_fd );
1587
+ add_assoc_long (return_value , "from_port" , from_sock -> addr .sin_port );
1588
+ }
1589
+ if (from_id != 0 )
1590
+ {
1591
+ add_assoc_long (return_value , "remote_port" , udp_info .port );
1592
+ }
1593
+ add_assoc_string (return_value , "remote_ip" , inet_ntoa (sin_addr ), 1 );
1594
+ return ;
1595
+ }
1595
1596
1596
- //connection is closed
1597
- if (conn -> active == 0 )
1598
- {
1599
- RETURN_FALSE ;
1600
- }
1601
- else
1602
- {
1603
- array_init (return_value );
1604
- add_assoc_long (return_value , "from_id" , conn -> from_id );
1605
- add_assoc_long (return_value , "from_fd" , conn -> from_fd );
1606
- add_assoc_long (return_value , "connect_time" , conn -> connect_time );
1607
- add_assoc_long (return_value , "last_time" , conn -> last_time );
1608
- add_assoc_long (return_value , "from_port" , serv -> connection_list [conn -> from_fd ].addr .sin_port );
1609
- add_assoc_long (return_value , "remote_port" , ntohs (conn -> addr .sin_port ));
1610
- add_assoc_string (return_value , "remote_ip" , inet_ntoa (conn -> addr .sin_addr ), 1 );
1611
- }
1597
+ //connection is closed
1598
+ if (conn -> active == 0 && ! noCheckConnection )
1599
+ {
1600
+ RETURN_FALSE ;
1601
+ }
1602
+ else
1603
+ {
1604
+ array_init (return_value );
1605
+ add_assoc_long (return_value , "from_id" , conn -> from_id );
1606
+ add_assoc_long (return_value , "from_fd" , conn -> from_fd );
1607
+ add_assoc_long (return_value , "connect_time" , conn -> connect_time );
1608
+ add_assoc_long (return_value , "last_time" , conn -> last_time );
1609
+ add_assoc_long (return_value , "from_port" , serv -> connection_list [conn -> from_fd ].addr .sin_port );
1610
+ add_assoc_long (return_value , "remote_port" , ntohs (conn -> addr .sin_port ));
1611
+ add_assoc_string (return_value , "remote_ip" , inet_ntoa (conn -> addr .sin_addr ), 1 );
1612
+ }
1612
1613
}
1613
1614
1614
1615
PHP_FUNCTION (swoole_connection_list )
0 commit comments