socket9 0.1.0-alpha.1

Extended untilities for the networking/unix sockets and raw network sockets
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/*-
 * socket9 - A RAW networking sockets manipulation and configration basing on 
 * strong types.
 * 
 * Copyright (C) 2021 Aleksandr Morozov, Lucia Hoffmann
 * Copyright (C) 2025 Aleksandr Morozov
 * 
 * The syslog-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016 OR
 *
 *   2. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *                     
 *   3. The MIT License (MIT)
 */

#[cfg(unix)]
use std::os::fd::OwnedFd;
use std::
{
    io::{self, IoSlice, IoSliceMut}, 
    marker::PhantomData, 
    net::{Shutdown, TcpListener, TcpStream, UdpSocket}, 
    time::Duration
};

#[cfg(unix)]
use crate::So9MarkerSockUnix;

use crate::
{
    AsOsDescr, So9MsgFlags, So9Marker, So9MarkerStateless, Socket9, Socket9ExtIp, Socket9ExtIp6, Socket9ExtIpTcp, Socket9ExtIpTcpExt, Socket9ExtSo, SocketTypeImps, address::IntoSockAddrSpec
};

/// A `read` part of the socket. Normally this structure contains a clonned
/// FD which is discarded when performing `unsplit`. If intance is `dropped`
/// the `read` channel of the socket closes.
///
/// The inner FD is in `nonblocking` mode.
#[derive(Debug)]
pub struct Socket9Read<SO: So9Marker>
{
    /// A socket's FD.
    so9: Option<Socket9<SO>>, 

    /// A ID which helps to identify the r/w endpoints when do unsplit
    orig_fd: <SO::SockType as SocketTypeImps>::RawType,

    /// Phantom.
    _p: PhantomData<SO>
}

impl<SO: So9Marker> Drop for Socket9Read<SO>
{
    fn drop(&mut self) 
    {
        // ignore errors
        let Some(socket) = self.so9.take()
        else { return };

        let _ = socket.shutdown(Shutdown::Read);
    }
}

impl<SO: So9Marker> Eq for Socket9Read<SO> {}

impl<SO: So9Marker> PartialEq for  Socket9Read<SO> 
{
    fn eq(&self, other: &Self) -> bool 
    {
        self.orig_fd == other.orig_fd && self._p == other._p
    }
}

impl<SO: So9Marker> PartialEq<Socket9Write<SO>> for  Socket9Read<SO> 
{
    fn eq(&self, other: &Socket9Write<SO>) -> bool 
    {
        self.orig_fd == other.orig_id
    }
}

#[cfg(unix)]
mod unix_spec_read
{
    use std::os::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};

    use super::*;

    impl<SO: So9Marker> AsFd for Socket9Read<SO>
    {
        fn as_fd(&self) -> BorrowedFd<'_> 
        {
            return self.so9.as_ref().unwrap().as_fd();
        }
    }

    impl<SO: So9Marker> AsRawFd for Socket9Read<SO>
    {
        fn as_raw_fd(&self) -> RawFd 
        {
            return self.so9.as_ref().unwrap().as_raw_fd();
        }
    }
}

#[cfg(windows)]
mod unix_spec_read
{
    use std::os::windows::io::{AsRawSocket, AsSocket, BorrowedSocket, RawSocket};

    use super::*;

    impl<SO: So9Marker> AsSocket for Socket9Read<SO>
    {
        fn as_socket(&self) -> BorrowedSocket<'_> 
        {
            return self.so9.as_ref().unwrap().as_socket();
        }
    }

    impl<SO: So9Marker> AsRawSocket for Socket9Read<SO>
    {
        fn as_raw_socket(&self) -> RawSocket 
        {
            return self.so9.as_ref().unwrap().as_raw_socket();
        }
    }
}

impl<SO: So9Marker> io::Read for Socket9Read<SO> 
{
    #[inline]
    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().recv(buf)
    }

    #[inline]
    fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().read_vectored(bufs)
    }
}

impl<'temp, SO: So9Marker> io::Read for &'temp Socket9Read<SO> 
{
    #[inline]
    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().recv(buf)
    }

    #[inline]
    fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().recv_vectored(bufs)
    }
}

impl<SO: So9Marker> Socket9Read<SO>
{
    /// Returns the socket's `local` address as type declared in
    /// `SO` [So9Marker::SockAddrType].
    #[inline]
    pub 
    fn local_addr(&self) -> io::Result<SO::SockAddrType>
    {
        self.so9.as_ref().unwrap().local_addr()
    }

    /// Returns the socket's `remote` address as type declared in
    /// `SO` [So9Marker::SockAddrType].
    #[inline]
    pub 
    fn peer_addr(&self) -> io::Result<SO::SockAddrType>
    {
        self.so9.as_ref().unwrap().peer_addr()
    }
}

#[cfg(unix)]
impl<SO: So9Marker> Socket9Read<SO>
{
    /// Reads the instance's socket FD `blocking` mode.
    #[inline]
    pub 
    fn is_nonblocking(&self) -> io::Result<bool>
    {
        self.so9.as_ref().unwrap().is_nonblocking()
    }

    /// Reads the instance's socket FD `cloexec` status.
    #[inline]
    pub 
    fn is_cloexec_sock(&self) -> io::Result<bool>
    {
        self.so9.as_ref().unwrap().is_cloexec_sock()
    }
}

impl<SO: So9Marker> Socket9Read<SO>
{
    /// Receives a data from socket to provided mutable slie of `u8`. 
    /// This function provides the `flags` from the `SO`generic which implements 
    /// [So9Marker::SOCK_RCV_FLAGS].
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes read into the buffer is returned.
    #[inline]
    pub 
    fn recv(&self, buffer: &mut[u8]) -> Result<usize, io::Error> 
    {
        self.so9.as_ref().unwrap().recv(buffer)
    }

    /// Receives a data from socket to provided mutable slie of `u8`. 
    /// User should provide the `flags` which will be passed 
    /// to `libc::send` function.
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes read into the buffer is returned.
    #[inline]
    pub 
    fn recv_with_flags(&self, buffer: &mut[u8], flags: i32) -> Result<usize, io::Error> 
    {
        self.so9.as_ref().unwrap().recv_with_flags(buffer, flags)
    }

    /// Receives an io_slices to the provided mutable slice of [IoSliceMut].
    /// Based on the `libc::readv`.
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes read into the buffer is returned.
    #[inline]
    pub 
    fn recv_vectored(&self,  bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().recv_vectored(bufs)
    }

    /// Peeks the data from the socket into the provided buffer without removing
    /// it from the socket.
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes read into the buffer is returned.
    #[inline]
    pub 
    fn peek(&self, buf: &mut [u8]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().peek(buf)
    }
}

impl<SO: So9Marker + So9MarkerStateless> Socket9Read<SO> 
{
    /// Peeks the data from the socket and writes it into provided mutable slice of `u8`
    /// without removing the data from socket and also returning the remote host info which
    /// is defined in the `SO` generic [So9Marker::SockAddrType].
    /// 
    /// # Returns 
    /// 
    /// The [io::Result] is returned.
    /// 
    /// On success, a tuple with `received size` anf `address` is returned.
    #[inline]
    pub 
    fn peek_from(&self, buf: &mut [u8]) -> io::Result<(usize, SO::SockAddrType)>
    {
        self.so9.as_ref().unwrap().peek_from(buf)
    }

    /// Receives the data from the socket and writes it into procided mutable slice of `u8`.
    /// Also returning the remote host info which is defined in the `SO` generic 
    /// [So9Marker::SockAddrType].
    /// 
    /// # Returns 
    /// 
    /// The [io::Result] is returned.
    /// 
    /// On success, a tuple with `received size` anf `address` is returned.
    #[inline]
    pub 
    fn recv_from(&self, buf: &mut [u8], flags: So9MsgFlags) -> io::Result<(usize, SO::SockAddrType)>
    {
        self.so9.as_ref().unwrap().recv_from(buf, flags)
    }

    /// Receives the data from the socket and writes it into procided mutable slice of `u8` before
    /// the specific tiemout.
    /// Also returning the remote host info which is defined in the `SO` generic 
    /// [So9Marker::SockAddrType].
    /// 
    /// # Returns 
    /// 
    /// The [io::Result] is returned.
    /// 
    /// On success, a tuple with `received size` anf `address` is returned.
    #[inline]
    pub 
    fn recv_from_timeout(&self, buf: &mut [u8], flags: So9MsgFlags, timeout: Duration) -> io::Result<(usize, SO::SockAddrType)>
    {
        self.so9.as_ref().unwrap().recv_from_flags_timeout(buf, flags, timeout)
    }
}

impl<SO: So9Marker> Socket9Read<SO>
{
    pub(crate) 
    fn new(so9: Socket9<SO>, orig_fd: <SO::SockType as SocketTypeImps>::RawType) -> Self
    {
        return 
            Self
            {
                so9: Some(so9),
                orig_fd: orig_fd,
                _p: PhantomData,
            };
    }

    pub(crate) 
    fn take(mut self) -> Socket9<SO>
    {
        return self.so9.take().unwrap();
    }
}

impl<SO: So9Marker> AsOsDescr for Socket9Read<SO>{}

// -- tcp listen
impl Socket9ExtSo for Socket9Read<TcpListener> {}
impl Socket9ExtIp for Socket9Read<TcpListener> {}
impl Socket9ExtIp6 for Socket9Read<TcpListener> {}

// -- tcp --
impl Socket9ExtSo for Socket9Read<TcpStream> {}
impl Socket9ExtIp for Socket9Read<TcpStream> {}
impl Socket9ExtIp6 for Socket9Read<TcpStream> {}
impl Socket9ExtIpTcp for Socket9Read<TcpStream> {}
impl Socket9ExtIpTcpExt for Socket9Read<TcpStream> {}

// -- udp socket--
impl Socket9ExtSo for Socket9Read<UdpSocket> {}
impl Socket9ExtIp for Socket9Read<UdpSocket> {}
impl Socket9ExtIp6 for Socket9Read<UdpSocket> {}

#[cfg(unix)]
pub mod unix_things
{
    use std::os::
    { 
        unix::net::{UnixDatagram, UnixListener, UnixStream}
    };

    use uds_fork::{UnixSeqpacketConn, UnixSeqpacketListener};

    use super::*;

    // -- unix datagram
    impl Socket9ExtSo for Socket9Read<UnixDatagram> {}

    // -- unix stream
    impl Socket9ExtSo for Socket9Read<UnixStream> {}

    // -- unix listener
    impl Socket9ExtSo for Socket9Read<UnixListener> {}

    // -- UnixSeqpacketListener --
    impl Socket9ExtSo for Socket9Read<UnixSeqpacketListener> {}

    // -- UnixSeqpacketConn --
    impl Socket9ExtSo for Socket9Read<UnixSeqpacketConn> {}
}

// -----------

/// A `write` part of the socket. Normally this structure contains a original
/// FD, not the clonend one. If intance is `dropped` the `write` channel of 
/// the socket closes.
/// 
/// The inner FD is in `nonblocking` mode.
#[derive(Debug)]
pub struct Socket9Write<SO: So9Marker>
{
    /// A socket's FD.
    so9: Option<Socket9<SO>>, 

    /// A ID which helps to identify the r/w endpoints when do unsplit
    orig_id: <SO::SockType as SocketTypeImps>::RawType,

    /// Phantom.
    _p: PhantomData<SO>
}

impl<SO: So9Marker> Drop for Socket9Write<SO>
{
    fn drop(&mut self) 
    {
        let Some(so9) = self.so9.take()
        else { return };

        // ignore errors
        let _ = so9.shutdown(Shutdown::Write);
    }
}

#[cfg(unix)]
mod unix_spec_write
{
    
    use std::os::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};

    use super::*;

    impl<SO: So9Marker> AsFd for Socket9Write<SO>
    {
        fn as_fd(&self) -> BorrowedFd<'_> 
        {
            return self.so9.as_ref().unwrap().as_fd();
        }
    }


    impl<SO: So9Marker> AsRawFd for Socket9Write<SO>
    {
        fn as_raw_fd(&self) -> RawFd 
        {
            return self.so9.as_ref().unwrap().as_raw_fd();
        }
    }
}

#[cfg(windows)]
mod unix_spec_write
{
    use std::os::windows::io::{AsRawSocket, AsSocket, BorrowedSocket, RawSocket};

    use crate::{So9Marker, socket_split::Socket9Write};

    impl<SO: So9Marker> AsSocket for Socket9Write<SO>
    {
        fn as_socket(&self) -> BorrowedSocket<'_> 
        {
            return self.so9.as_ref().unwrap().as_socket();
        }
    }

    impl<SO: So9Marker> AsRawSocket for Socket9Write<SO>
    {
        fn as_raw_socket(&self) -> RawSocket 
        {
            return self.so9.as_ref().unwrap().as_raw_socket();
        }
    }
}


impl<SO: So9Marker> io::Write for Socket9Write<SO> 
{
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send(buf)
    }

    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send_vectored(bufs)
    }

    fn flush(&mut self) -> io::Result<()> 
    {
        Ok(())
    }
}

impl<'temp, SO: So9Marker> io::Write for &'temp Socket9Write<SO>
{
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send(buf)
    }

    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send_vectored(bufs)
    }

    fn flush(&mut self) -> io::Result<()> 
    {
        Ok(())
    }
}

impl<SO: So9Marker> Socket9Write<SO>
{
    pub(crate) 
    fn new(so9: Socket9<SO>, orig_id: <SO::SockType as SocketTypeImps>::RawType) -> Self
    {
        return 
            Self
            {
                so9: Some(so9),
                orig_id: orig_id,
                _p: PhantomData,
            };
    }

    pub(crate) 
    fn take(mut self) -> Socket9<SO>
    {
        return self.so9.take().unwrap();
    }
}

impl<SO: So9Marker> Socket9Write<SO>
{
    /// Returns the socket's `local` address as type declared in
    /// `SO` [So9Marker::SockAddrType].
    #[inline]
    pub 
    fn local_addr(&self) -> io::Result<SO::SockAddrType>
    {
        self.so9.as_ref().unwrap().local_addr()
    }

    /// Returns the socket's `remote` address as type declared in
    /// `SO` [So9Marker::SockAddrType].
    #[inline]
    pub 
    fn peer_addr(&self) -> io::Result<SO::SockAddrType>
    {
        self.so9.as_ref().unwrap().peer_addr()
    }
}

#[cfg(unix)]
impl<SO: So9Marker> Socket9Write<SO>
{
    /// Reads the instance's socket FD `blocking` mode.
    #[inline]
    pub 
    fn is_nonblocking(&self) -> io::Result<bool>
    {
        self.so9.as_ref().unwrap().is_nonblocking()
    }

    /// Reads the instance's socket FD `cloexec` status.
    #[inline]
    pub 
    fn is_cloexec_sock(&self) -> io::Result<bool>
    {
        self.so9.as_ref().unwrap().is_cloexec_sock()
    }
}

impl<SO: So9Marker> Socket9Write<SO>
{
    /// Performs a generic `send` operation of the provided buffer to
    /// the remote host. This function provides the `flags` from the 
    /// `SO`generic which implements [So9Marker::SOCK_SND_FLAGS].
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes written to the socket is returned.
    #[inline]
    pub 
    fn send(&self, data: &[u8]) -> Result<usize, io::Error> 
    {
        self.so9.as_ref().unwrap().send(data)
    }

    /// Performs a generic `send` operation of the provided buffer to
    /// the remote host. User should provide the `flags` which will be passed 
    /// to `libc::send` function.
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes written to the socket is returned.
    #[inline]
    pub 
    fn send_with_flags(&self, data: &[u8], flags: So9MsgFlags) -> Result<usize, io::Error> 
    {
        self.so9.as_ref().unwrap().send_with_flags(data, flags)
    }

    /// Performes a `vectorized` send of [IoSlice] slice. This function
    /// calls the `libc::writev`.
    /// 
    /// # Returns 
    /// 
    /// An amount of bytes written to the socket is returned.
    #[inline]
    pub 
    fn send_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send_vectored(bufs)
    }

}

impl<SO: So9Marker + So9MarkerStateless> Socket9Write<SO> 
{
    /// Sends the data from the provided buffer to specified destination
    /// `addr_to`. This function uses the flags from the implementation of
    /// the `SO` generic [So9Marker::SOCK_SND_FLAGS].
    /// 
    /// # Generics
    /// 
    /// `S` - [IntoSockAddrSpec] for the `SO` declared type. It accepts the
    /// address as type `str` or `path` depending on the `SO`.
    /// 
    /// # Returns 
    /// 
    /// The [io::Result] is returned. On success the amount of written
    /// bytes is returned.
    /// 
    /// # Example
    /// 
    /// ```ignore
    /// let snd_part = Socket9::<UnixDatagram>::new(So9DomainUnix::Unix).unwrap();
    /// 
    /// let data = [1,2,3,4];
    /// let snt_n = snd_part.send_to(&data[..3], &test_path).unwrap();
    /// ```
    #[inline]
    pub 
    fn send_to<S>(&self, buf: &[u8], addr_to: &S) -> io::Result<usize>
    where 
        S: IntoSockAddrSpec<SO::SockAddrType>
    {
        self.so9.as_ref().unwrap().send_to(buf, addr_to)
    }

    /// Sends the data from the provided buffer to specified destination
    /// `addr_to`. This function requires user to provide a flags which 
    /// will be passed to `libc::sendto`.
    /// 
    /// # Generics
    /// 
    /// `S` - [IntoSockAddrSpec] for the `SO` declared type. It accepts the
    /// address as type `str` or `path` depending on the `SO`.
    /// 
    /// # Returns 
    /// 
    /// The [io::Result] is returned. On success the amount of written
    /// bytes is returned.
    #[inline]
    pub 
    fn send_to_with_flags<S>(&self, buf: &[u8], addr_to: &S, flags: i32) -> io::Result<usize>
    where 
        S: IntoSockAddrSpec<SO::SockAddrType>
    {
        self.so9.as_ref().unwrap().send_to_with_flags(buf, addr_to, flags)
    }
}

#[cfg(unix)]
impl<SO: So9Marker + So9MarkerSockUnix> Socket9Write<SO> 
{
    /// Sends a packet assembled from multiple byte slices. This is a `unix` specific
    /// type of message which uses a [libc::sendmsg].  This function uses the flags from 
    /// the implementation of the `SO` generic [So9Marker::SOCK_SND_VECT_FLAGS].
    /// 
    /// # Returns
    /// 
    /// The [io::Result] is returned, where on success the amount of sent bytes
    /// is returned.
    #[inline]
    pub 
    fn send_vectored_with(&self, slices: &[IoSlice]) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send_vectored_with(slices)
    }

    /// Sends a packet assembled from multiple byte slices. This is a `unix` specific
    /// type of message which uses a [libc::sendmsg].  This function requires that 
    /// the user provides the flags which will be passed to `sendmsg`.
    /// 
    /// # Returns
    /// 
    /// The [io::Result] is returned, where on success the amount of sent bytes
    /// is returned.
    #[inline]
    pub 
    fn send_vectored_with_flags(&self, slices: &[IoSlice], flags: So9MsgFlags) -> io::Result<usize> 
    {
        self.so9.as_ref().unwrap().send_vectored_with_flags(slices, flags)
    }
}

#[cfg(unix)]
impl<SO: So9Marker + So9MarkerSockUnix> Socket9Write<SO> 
{
    /// Transfers the `FD` over the wire to other endpoint. This is a `unix` specific
    /// type of message which uses a [libc::sendmsg]. This function uses the flags from 
    /// the implementation of the `SO` generic [So9Marker::SOCK_SND_FLAGS].
    /// 
    /// # Returns
    /// 
    /// The [io::Result] is returned, where on success the amount of sent bytes
    /// is returned.
    #[inline]
    pub 
    fn send_fd(&self, fd: OwnedFd) -> io::Result<usize>
    {
        self.so9.as_ref().unwrap().send_fd(fd)
    }

    /// Transfers the `FD` over the wire to other endpoint.This is a `unix` specific
    /// type of message which uses a [libc::sendmsg]. This function requires that 
    /// the user provides the flags which will be passed to `sendmsg`.
    /// 
    /// # Returns
    /// 
    /// The [io::Result] is returned, where on success the amount of sent bytes
    /// is returned.
    #[inline]
    pub 
    fn send_fd_with_flags(&self, fd: OwnedFd, flags: So9MsgFlags) -> io::Result<usize>
    {
        self.so9.as_ref().unwrap().send_fd_with_flags(fd, flags)
    }
}

impl<SO: So9Marker> AsOsDescr for Socket9Write<SO>{}

// -- tcp listen
impl Socket9ExtSo for Socket9Write<TcpListener> {}
impl Socket9ExtIp for Socket9Write<TcpListener> {}
impl Socket9ExtIp6 for Socket9Write<TcpListener> {}

// -- tcp --
impl Socket9ExtSo for Socket9Write<TcpStream> {}
impl Socket9ExtIp for Socket9Write<TcpStream> {}
impl Socket9ExtIp6 for Socket9Write<TcpStream> {}
impl Socket9ExtIpTcp for Socket9Write<TcpStream> {}
impl Socket9ExtIpTcpExt for Socket9Write<TcpStream> {}

// -- udp socket--
impl Socket9ExtSo for Socket9Write<UdpSocket> {}
impl Socket9ExtIp for Socket9Write<UdpSocket> {}
impl Socket9ExtIp6 for Socket9Write<UdpSocket> {}

#[cfg(unix)]
pub mod unix_things_w
{
    use std::os::
    {
        unix::net::{UnixDatagram, UnixListener, UnixStream}
    };

    use uds_fork::{UnixSeqpacketConn, UnixSeqpacketListener};

    use super::*;

    // -- unix datagram
    impl Socket9ExtSo for Socket9Write<UnixDatagram> {}

    // -- unix stream
    impl Socket9ExtSo for Socket9Write<UnixStream> {}

    // -- unix listener
    impl Socket9ExtSo for Socket9Write<UnixListener> {}

    // -- UnixSeqpacketListener --
    impl Socket9ExtSo for Socket9Write<UnixSeqpacketListener> {}

    // -- UnixSeqpacketConn --
    impl Socket9ExtSo for Socket9Write<UnixSeqpacketConn> {}
}