@@ -56,6 +56,8 @@ public Libuv()
56
56
_uv_req_size = NativeDarwinMonoMethods . uv_req_size ;
57
57
_uv_ip4_addr = NativeDarwinMonoMethods . uv_ip4_addr ;
58
58
_uv_ip6_addr = NativeDarwinMonoMethods . uv_ip6_addr ;
59
+ _uv_tcp_getpeername = NativeDarwinMonoMethods . uv_tcp_getpeername ;
60
+ _uv_tcp_getsockname = NativeDarwinMonoMethods . uv_tcp_getsockname ;
59
61
_uv_walk = NativeDarwinMonoMethods . uv_walk ;
60
62
}
61
63
else
@@ -95,6 +97,8 @@ public Libuv()
95
97
_uv_req_size = NativeMethods . uv_req_size ;
96
98
_uv_ip4_addr = NativeMethods . uv_ip4_addr ;
97
99
_uv_ip6_addr = NativeMethods . uv_ip6_addr ;
100
+ _uv_tcp_getpeername = NativeMethods . uv_tcp_getpeername ;
101
+ _uv_tcp_getsockname = NativeMethods . uv_tcp_getsockname ;
98
102
_uv_walk = NativeMethods . uv_walk ;
99
103
}
100
104
}
@@ -206,9 +210,9 @@ public void tcp_init(UvLoopHandle loop, UvTcpHandle handle)
206
210
Check ( _uv_tcp_init ( loop , handle ) ) ;
207
211
}
208
212
209
- protected delegate int uv_tcp_bind_func ( UvTcpHandle handle , ref sockaddr addr , int flags ) ;
213
+ protected delegate int uv_tcp_bind_func ( UvTcpHandle handle , ref SockAddr addr , int flags ) ;
210
214
protected uv_tcp_bind_func _uv_tcp_bind ;
211
- public void tcp_bind ( UvTcpHandle handle , ref sockaddr addr , int flags )
215
+ public void tcp_bind ( UvTcpHandle handle , ref SockAddr addr , int flags )
212
216
{
213
217
handle . Validate ( ) ;
214
218
Check ( _uv_tcp_bind ( handle , ref addr , flags ) ) ;
@@ -365,16 +369,16 @@ public int req_size(RequestType reqType)
365
369
return _uv_req_size ( reqType ) ;
366
370
}
367
371
368
- protected delegate int uv_ip4_addr_func ( string ip , int port , out sockaddr addr ) ;
372
+ protected delegate int uv_ip4_addr_func ( string ip , int port , out SockAddr addr ) ;
369
373
protected uv_ip4_addr_func _uv_ip4_addr ;
370
- public int ip4_addr ( string ip , int port , out sockaddr addr , out Exception error )
374
+ public int ip4_addr ( string ip , int port , out SockAddr addr , out Exception error )
371
375
{
372
376
return Check ( _uv_ip4_addr ( ip , port , out addr ) , out error ) ;
373
377
}
374
378
375
- protected delegate int uv_ip6_addr_func ( string ip , int port , out sockaddr addr ) ;
379
+ protected delegate int uv_ip6_addr_func ( string ip , int port , out SockAddr addr ) ;
376
380
protected uv_ip6_addr_func _uv_ip6_addr ;
377
- public int ip6_addr ( string ip , int port , out sockaddr addr , out Exception error )
381
+ public int ip6_addr ( string ip , int port , out SockAddr addr , out Exception error )
378
382
{
379
383
return Check ( _uv_ip6_addr ( ip , port , out addr ) , out error ) ;
380
384
}
@@ -388,24 +392,25 @@ unsafe public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg)
388
392
_uv_walk ( loop , walk_cb , arg ) ;
389
393
}
390
394
391
- public uv_buf_t buf_init ( IntPtr memory , int len )
395
+ public delegate int uv_tcp_getsockname_func ( UvTcpHandle handle , out SockAddr addr , ref int namelen ) ;
396
+ protected uv_tcp_getsockname_func _uv_tcp_getsockname ;
397
+ public void tcp_getsockname ( UvTcpHandle handle , out SockAddr addr , ref int namelen )
392
398
{
393
- return new uv_buf_t ( memory , len , IsWindows ) ;
399
+ handle . Validate ( ) ;
400
+ Check ( _uv_tcp_getsockname ( handle , out addr , ref namelen ) ) ;
394
401
}
395
402
396
- public struct sockaddr
403
+ public delegate int uv_tcp_getpeername_func ( UvTcpHandle handle , out SockAddr addr , ref int namelen ) ;
404
+ protected uv_tcp_getpeername_func _uv_tcp_getpeername ;
405
+ public void tcp_getpeername ( UvTcpHandle handle , out SockAddr addr , ref int namelen )
397
406
{
398
- // this type represents native memory occupied by sockaddr struct
399
- // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx
400
- // although the c/c++ header defines it as a 2-byte short followed by a 14-byte array,
401
- // the simplest way to reserve the same size in c# is with four nameless long values
402
-
403
- private long _field0 ;
404
- private long _field1 ;
405
- private long _field2 ;
406
- private long _field3 ;
407
+ handle . Validate ( ) ;
408
+ Check ( _uv_tcp_getpeername ( handle , out addr , ref namelen ) ) ;
409
+ }
407
410
408
- public sockaddr ( long ignored ) { _field3 = _field0 = _field1 = _field2 = _field3 = 0 ; }
411
+ public uv_buf_t buf_init ( IntPtr memory , int len )
412
+ {
413
+ return new uv_buf_t ( memory , len , IsWindows ) ;
409
414
}
410
415
411
416
public struct uv_buf_t
@@ -504,7 +509,7 @@ private static class NativeMethods
504
509
public static extern int uv_tcp_init ( UvLoopHandle loop , UvTcpHandle handle ) ;
505
510
506
511
[ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
507
- public static extern int uv_tcp_bind ( UvTcpHandle handle , ref sockaddr addr , int flags ) ;
512
+ public static extern int uv_tcp_bind ( UvTcpHandle handle , ref SockAddr addr , int flags ) ;
508
513
509
514
[ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
510
515
public static extern int uv_tcp_open ( UvTcpHandle handle , IntPtr hSocket ) ;
@@ -564,10 +569,16 @@ private static class NativeMethods
564
569
public static extern int uv_req_size ( RequestType reqType ) ;
565
570
566
571
[ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
567
- public static extern int uv_ip4_addr ( string ip , int port , out sockaddr addr ) ;
572
+ public static extern int uv_ip4_addr ( string ip , int port , out SockAddr addr ) ;
568
573
569
574
[ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
570
- public static extern int uv_ip6_addr ( string ip , int port , out sockaddr addr ) ;
575
+ public static extern int uv_ip6_addr ( string ip , int port , out SockAddr addr ) ;
576
+
577
+ [ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
578
+ public static extern int uv_tcp_getsockname ( UvTcpHandle handle , out SockAddr name , ref int namelen ) ;
579
+
580
+ [ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
581
+ public static extern int uv_tcp_getpeername ( UvTcpHandle handle , out SockAddr name , ref int namelen ) ;
571
582
572
583
[ DllImport ( "libuv" , CallingConvention = CallingConvention . Cdecl ) ]
573
584
unsafe public static extern int uv_walk ( UvLoopHandle loop , uv_walk_cb walk_cb , IntPtr arg ) ;
@@ -606,7 +617,7 @@ private static class NativeDarwinMonoMethods
606
617
public static extern int uv_tcp_init ( UvLoopHandle loop , UvTcpHandle handle ) ;
607
618
608
619
[ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
609
- public static extern int uv_tcp_bind ( UvTcpHandle handle , ref sockaddr addr , int flags ) ;
620
+ public static extern int uv_tcp_bind ( UvTcpHandle handle , ref SockAddr addr , int flags ) ;
610
621
611
622
[ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
612
623
public static extern int uv_tcp_open ( UvTcpHandle handle , IntPtr hSocket ) ;
@@ -666,10 +677,16 @@ private static class NativeDarwinMonoMethods
666
677
public static extern int uv_req_size ( RequestType reqType ) ;
667
678
668
679
[ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
669
- public static extern int uv_ip4_addr ( string ip , int port , out sockaddr addr ) ;
680
+ public static extern int uv_ip4_addr ( string ip , int port , out SockAddr addr ) ;
681
+
682
+ [ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
683
+ public static extern int uv_ip6_addr ( string ip , int port , out SockAddr addr ) ;
684
+
685
+ [ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
686
+ public static extern int uv_tcp_getsockname ( UvTcpHandle handle , out SockAddr name , ref int namelen ) ;
670
687
671
688
[ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
672
- public static extern int uv_ip6_addr ( string ip , int port , out sockaddr addr ) ;
689
+ public static extern int uv_tcp_getpeername ( UvTcpHandle handle , out SockAddr name , ref int namelen ) ;
673
690
674
691
[ DllImport ( "__Internal" , CallingConvention = CallingConvention . Cdecl ) ]
675
692
unsafe public static extern int uv_walk ( UvLoopHandle loop , uv_walk_cb walk_cb , IntPtr arg ) ;
0 commit comments