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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{WebsocketConnectionType, WebsocketExtension, WebsocketState};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// The WebSocket Protocol
    ///
    /// Provides support for the [WebSocket](http://tools.ietf.org/html/rfc6455)
    /// protocol.
    ///
    /// To connect to a WebSocket server, create a [`Session`][crate::Session] and call
    /// `Session::websocket_connect_async()`. To accept WebSocket
    /// connections, create a [`Server`][crate::Server] and add a handler to it with
    /// [`ServerExtManual::add_websocket_handler()`][crate::prelude::ServerExtManual::add_websocket_handler()].
    ///
    /// (Lower-level support is available via
    /// `websocket_client_prepare_handshake()` and
    /// `websocket_client_verify_handshake()`, for handling the client side of the
    /// WebSocket handshake, and `websocket_server_process_handshake()` for
    /// handling the server side.)
    ///
    /// #SoupWebsocketConnection handles the details of WebSocket communication. You
    /// can use [`send_text()`][Self::send_text()] and
    /// `WebsocketConnection::send_binary()` to send data, and the
    /// [`message`][struct@crate::WebsocketConnection#message] signal to receive data.
    /// (#SoupWebsocketConnection currently only supports asynchronous I/O.)
    ///
    /// ## Properties
    ///
    ///
    /// #### `connection-type`
    ///  The type of connection (client/server).
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `extensions`
    ///  List of [`WebsocketExtension`][crate::WebsocketExtension] objects that are active in the connection.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `io-stream`
    ///  The underlying IO stream the WebSocket is communicating
    /// over.
    ///
    /// The input and output streams must be pollable streams.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `keepalive-interval`
    ///  Interval in seconds on when to send a ping message which will
    /// serve as a keepalive message.
    ///
    /// If set to 0 the keepalive message is disabled.
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `keepalive-pong-timeout`
    ///  Timeout in seconds for when the absence of a pong from a keepalive
    /// ping is assumed to be caused by a faulty connection. The WebSocket
    /// will be transitioned to a closed state when this happens.
    ///
    /// If set to 0 then the absence of pongs from keepalive pings is
    /// ignored.
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `max-incoming-payload-size`
    ///  The maximum payload size for incoming packets.
    ///
    /// The protocol expects or 0 to not limit it.
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `origin`
    ///  The client's Origin.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `protocol`
    ///  The chosen protocol, or [`None`] if a protocol was not agreed
    /// upon.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `state`
    ///  The current state of the WebSocket.
    ///
    /// Readable
    ///
    ///
    /// #### `uri`
    ///  The URI of the WebSocket.
    ///
    /// For servers this represents the address of the WebSocket,
    /// and for clients it is the address connected to.
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// ## Signals
    ///
    ///
    /// #### `closed`
    ///  Emitted when the connection has completely closed.
    ///
    /// This happens either due to an orderly close from the peer, one
    /// initiated via [`WebsocketConnection::close()`][crate::WebsocketConnection::close()] or a fatal error
    /// condition that caused a close.
    ///
    /// This signal will be emitted once.
    ///
    ///
    ///
    ///
    /// #### `closing`
    ///  This signal will be emitted during an orderly close.
    ///
    ///
    ///
    ///
    /// #### `error`
    ///  Emitted when an error occurred on the WebSocket.
    ///
    /// This may be fired multiple times. Fatal errors will be followed by
    /// the [`closed`][struct@crate::WebsocketConnection#closed] signal being emitted.
    ///
    ///
    ///
    ///
    /// #### `message`
    ///  Emitted when we receive a message from the peer.
    ///
    /// As a convenience, the @message data will always be
    /// [`None`]-terminated, but the NUL byte will not be included in
    /// the length count.
    ///
    ///
    ///
    ///
    /// #### `pong`
    ///  Emitted when we receive a Pong frame (solicited or
    /// unsolicited) from the peer.
    ///
    /// As a convenience, the @message data will always be
    /// [`None`]-terminated, but the NUL byte will not be included in
    /// the length count.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`WebsocketConnectionExtManual`][trait@crate::prelude::WebsocketConnectionExtManual]
    #[doc(alias = "SoupWebsocketConnection")]
    pub struct WebsocketConnection(Object<ffi::SoupWebsocketConnection, ffi::SoupWebsocketConnectionClass>);

    match fn {
        type_ => || ffi::soup_websocket_connection_get_type(),
    }
}

impl WebsocketConnection {
    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`WebsocketConnection`] objects.
    ///
    /// This method returns an instance of [`WebsocketConnectionBuilder`](crate::builders::WebsocketConnectionBuilder) which can be used to create [`WebsocketConnection`] objects.
    pub fn builder() -> WebsocketConnectionBuilder {
        WebsocketConnectionBuilder::new()
    }

    /// Close the connection in an orderly fashion.
    ///
    /// Note that until the [`closed`][struct@crate::WebsocketConnection#closed] signal fires, the connection
    /// is not yet completely closed. The close message is not even sent until the
    /// main loop runs.
    ///
    /// The @code and @data are sent to the peer along with the close request.
    /// If @code is [`WebsocketCloseCode::NoStatus`][crate::WebsocketCloseCode::NoStatus] a close message with no body
    /// (without code and data) is sent.
    /// Note that the @data must be UTF-8 valid.
    /// ## `code`
    /// close code
    /// ## `data`
    /// close data
    #[doc(alias = "soup_websocket_connection_close")]
    pub fn close(&self, code: libc::c_ushort, data: Option<&str>) {
        unsafe {
            ffi::soup_websocket_connection_close(
                self.to_glib_none().0,
                code,
                data.to_glib_none().0,
            );
        }
    }

    /// Get the close code received from the WebSocket peer.
    ///
    /// This only becomes valid once the WebSocket is in the
    /// [`WebsocketState::Closed`][crate::WebsocketState::Closed] state. The value will often be in the
    /// [`WebsocketCloseCode`][crate::WebsocketCloseCode] enumeration, but may also be an application
    /// defined close code.
    ///
    /// # Returns
    ///
    /// the close code or zero.
    #[doc(alias = "soup_websocket_connection_get_close_code")]
    #[doc(alias = "get_close_code")]
    pub fn close_code(&self) -> libc::c_ushort {
        unsafe { ffi::soup_websocket_connection_get_close_code(self.to_glib_none().0) }
    }

    /// Get the close data received from the WebSocket peer.
    ///
    /// This only becomes valid once the WebSocket is in the
    /// [`WebsocketState::Closed`][crate::WebsocketState::Closed] state. The data may be freed once
    /// the main loop is run, so copy it if you need to keep it around.
    ///
    /// # Returns
    ///
    /// the close data or [`None`]
    #[doc(alias = "soup_websocket_connection_get_close_data")]
    #[doc(alias = "get_close_data")]
    pub fn close_data(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::soup_websocket_connection_get_close_data(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the connection type (client/server) of the connection.
    ///
    /// # Returns
    ///
    /// the connection type
    #[doc(alias = "soup_websocket_connection_get_connection_type")]
    #[doc(alias = "get_connection_type")]
    pub fn connection_type(&self) -> WebsocketConnectionType {
        unsafe {
            from_glib(ffi::soup_websocket_connection_get_connection_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the extensions chosen via negotiation with the peer.
    ///
    /// # Returns
    ///
    /// a #GList of #SoupWebsocketExtension objects
    #[doc(alias = "soup_websocket_connection_get_extensions")]
    #[doc(alias = "get_extensions")]
    pub fn extensions(&self) -> Vec<WebsocketExtension> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::soup_websocket_connection_get_extensions(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the I/O stream the WebSocket is communicating over.
    ///
    /// # Returns
    ///
    /// the WebSocket's I/O stream.
    #[doc(alias = "soup_websocket_connection_get_io_stream")]
    #[doc(alias = "get_io_stream")]
    pub fn io_stream(&self) -> Option<gio::IOStream> {
        unsafe {
            from_glib_none(ffi::soup_websocket_connection_get_io_stream(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the keepalive interval in seconds or 0 if disabled.
    ///
    /// # Returns
    ///
    /// the keepalive interval.
    #[doc(alias = "soup_websocket_connection_get_keepalive_interval")]
    #[doc(alias = "get_keepalive_interval")]
    pub fn keepalive_interval(&self) -> u32 {
        unsafe { ffi::soup_websocket_connection_get_keepalive_interval(self.to_glib_none().0) }
    }

    /// Gets the keepalive pong timeout in seconds or 0 if disabled.
    ///
    /// # Returns
    ///
    /// the keepalive pong timeout.
    #[cfg(feature = "v3_6")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
    #[doc(alias = "soup_websocket_connection_get_keepalive_pong_timeout")]
    #[doc(alias = "get_keepalive_pong_timeout")]
    pub fn keepalive_pong_timeout(&self) -> u32 {
        unsafe { ffi::soup_websocket_connection_get_keepalive_pong_timeout(self.to_glib_none().0) }
    }

    /// Gets the maximum payload size allowed for incoming packets.
    ///
    /// # Returns
    ///
    /// the maximum payload size.
    #[doc(alias = "soup_websocket_connection_get_max_incoming_payload_size")]
    #[doc(alias = "get_max_incoming_payload_size")]
    pub fn max_incoming_payload_size(&self) -> u64 {
        unsafe {
            ffi::soup_websocket_connection_get_max_incoming_payload_size(self.to_glib_none().0)
        }
    }

    /// Get the origin of the WebSocket.
    ///
    /// # Returns
    ///
    /// the origin
    #[doc(alias = "soup_websocket_connection_get_origin")]
    #[doc(alias = "get_origin")]
    pub fn origin(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::soup_websocket_connection_get_origin(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the protocol chosen via negotiation with the peer.
    ///
    /// # Returns
    ///
    /// the chosen protocol
    #[doc(alias = "soup_websocket_connection_get_protocol")]
    #[doc(alias = "get_protocol")]
    pub fn protocol(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::soup_websocket_connection_get_protocol(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the current state of the WebSocket.
    ///
    /// # Returns
    ///
    /// the state
    #[doc(alias = "soup_websocket_connection_get_state")]
    #[doc(alias = "get_state")]
    pub fn state(&self) -> WebsocketState {
        unsafe {
            from_glib(ffi::soup_websocket_connection_get_state(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the URI of the WebSocket.
    ///
    /// For servers this represents the address of the WebSocket, and
    /// for clients it is the address connected to.
    ///
    /// # Returns
    ///
    /// the URI
    #[doc(alias = "soup_websocket_connection_get_uri")]
    #[doc(alias = "get_uri")]
    pub fn uri(&self) -> Option<glib::Uri> {
        unsafe {
            from_glib_none(ffi::soup_websocket_connection_get_uri(
                self.to_glib_none().0,
            ))
        }
    }

    /// Send a [`None`]-terminated text (UTF-8) message to the peer.
    ///
    /// If you need to send text messages containing [`None`] characters use
    /// `WebsocketConnection::send_message()` instead.
    ///
    /// The message is queued to be sent and will be sent when the main loop
    /// is run.
    /// ## `text`
    /// the message contents
    #[doc(alias = "soup_websocket_connection_send_text")]
    pub fn send_text(&self, text: &str) {
        unsafe {
            ffi::soup_websocket_connection_send_text(self.to_glib_none().0, text.to_glib_none().0);
        }
    }

    /// Sets the interval in seconds on when to send a ping message which will serve
    /// as a keepalive message.
    ///
    /// If set to 0 the keepalive message is disabled.
    /// ## `interval`
    /// the interval to send a ping message or 0 to disable it
    #[doc(alias = "soup_websocket_connection_set_keepalive_interval")]
    pub fn set_keepalive_interval(&self, interval: u32) {
        unsafe {
            ffi::soup_websocket_connection_set_keepalive_interval(self.to_glib_none().0, interval);
        }
    }

    /// Set the timeout in seconds for when the absence of a pong from a keepalive
    /// ping is assumed to be caused by a faulty connection.
    ///
    /// If set to 0 then the absence of pongs from keepalive pings is ignored.
    /// ## `pong_timeout`
    /// the timeout in seconds
    #[cfg(feature = "v3_6")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
    #[doc(alias = "soup_websocket_connection_set_keepalive_pong_timeout")]
    pub fn set_keepalive_pong_timeout(&self, pong_timeout: u32) {
        unsafe {
            ffi::soup_websocket_connection_set_keepalive_pong_timeout(
                self.to_glib_none().0,
                pong_timeout,
            );
        }
    }

    /// Sets the maximum payload size allowed for incoming packets.
    ///
    /// It does not limit the outgoing packet size.
    /// ## `max_incoming_payload_size`
    /// the maximum payload size
    #[doc(alias = "soup_websocket_connection_set_max_incoming_payload_size")]
    pub fn set_max_incoming_payload_size(&self, max_incoming_payload_size: u64) {
        unsafe {
            ffi::soup_websocket_connection_set_max_incoming_payload_size(
                self.to_glib_none().0,
                max_incoming_payload_size,
            );
        }
    }

    /// Emitted when the connection has completely closed.
    ///
    /// This happens either due to an orderly close from the peer, one
    /// initiated via [`close()`][Self::close()] or a fatal error
    /// condition that caused a close.
    ///
    /// This signal will be emitted once.
    #[doc(alias = "closed")]
    pub fn connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn closed_trampoline<F: Fn(&WebsocketConnection) + 'static>(
            this: *mut ffi::SoupWebsocketConnection,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"closed\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    closed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// This signal will be emitted during an orderly close.
    #[doc(alias = "closing")]
    pub fn connect_closing<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn closing_trampoline<F: Fn(&WebsocketConnection) + 'static>(
            this: *mut ffi::SoupWebsocketConnection,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"closing\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    closing_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when an error occurred on the WebSocket.
    ///
    /// This may be fired multiple times. Fatal errors will be followed by
    /// the [`closed`][struct@crate::WebsocketConnection#closed] signal being emitted.
    /// ## `error`
    /// the error that occured
    #[doc(alias = "error")]
    pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn error_trampoline<
            F: Fn(&WebsocketConnection, &glib::Error) + 'static,
        >(
            this: *mut ffi::SoupWebsocketConnection,
            error: *mut glib::ffi::GError,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(error))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"error\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    error_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when we receive a message from the peer.
    ///
    /// As a convenience, the @message data will always be
    /// [`None`]-terminated, but the NUL byte will not be included in
    /// the length count.
    /// ## `type_`
    /// the type of message contents
    /// ## `message`
    /// the message data
    #[doc(alias = "message")]
    pub fn connect_message<F: Fn(&Self, i32, &glib::Bytes) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn message_trampoline<
            F: Fn(&WebsocketConnection, i32, &glib::Bytes) + 'static,
        >(
            this: *mut ffi::SoupWebsocketConnection,
            type_: libc::c_int,
            message: *mut glib::ffi::GBytes,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), type_, &from_glib_borrow(message))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"message\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    message_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when we receive a Pong frame (solicited or
    /// unsolicited) from the peer.
    ///
    /// As a convenience, the @message data will always be
    /// [`None`]-terminated, but the NUL byte will not be included in
    /// the length count.
    /// ## `message`
    /// the application data (if any)
    #[doc(alias = "pong")]
    pub fn connect_pong<F: Fn(&Self, &glib::Bytes) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn pong_trampoline<
            F: Fn(&WebsocketConnection, &glib::Bytes) + 'static,
        >(
            this: *mut ffi::SoupWebsocketConnection,
            message: *mut glib::ffi::GBytes,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(message))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"pong\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    pong_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "keepalive-interval")]
    pub fn connect_keepalive_interval_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_keepalive_interval_trampoline<
            F: Fn(&WebsocketConnection) + 'static,
        >(
            this: *mut ffi::SoupWebsocketConnection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::keepalive-interval\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_keepalive_interval_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v3_6")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
    #[doc(alias = "keepalive-pong-timeout")]
    pub fn connect_keepalive_pong_timeout_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_keepalive_pong_timeout_trampoline<
            F: Fn(&WebsocketConnection) + 'static,
        >(
            this: *mut ffi::SoupWebsocketConnection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::keepalive-pong-timeout\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_keepalive_pong_timeout_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "max-incoming-payload-size")]
    pub fn connect_max_incoming_payload_size_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_max_incoming_payload_size_trampoline<
            F: Fn(&WebsocketConnection) + 'static,
        >(
            this: *mut ffi::SoupWebsocketConnection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::max-incoming-payload-size\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_max_incoming_payload_size_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "state")]
    pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_state_trampoline<F: Fn(&WebsocketConnection) + 'static>(
            this: *mut ffi::SoupWebsocketConnection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::state\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_state_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`WebsocketConnection`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct WebsocketConnectionBuilder {
    builder: glib::object::ObjectBuilder<'static, WebsocketConnection>,
}

impl WebsocketConnectionBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// The type of connection (client/server).
    pub fn connection_type(self, connection_type: WebsocketConnectionType) -> Self {
        Self {
            builder: self.builder.property("connection-type", connection_type),
        }
    }

    //pub fn extensions(self, extensions: /*Unimplemented*/Basic: Pointer) -> Self {
    //    Self { builder: self.builder.property("extensions", extensions), }
    //}

    /// The underlying IO stream the WebSocket is communicating
    /// over.
    ///
    /// The input and output streams must be pollable streams.
    pub fn io_stream(self, io_stream: &impl IsA<gio::IOStream>) -> Self {
        Self {
            builder: self
                .builder
                .property("io-stream", io_stream.clone().upcast()),
        }
    }

    /// Interval in seconds on when to send a ping message which will
    /// serve as a keepalive message.
    ///
    /// If set to 0 the keepalive message is disabled.
    pub fn keepalive_interval(self, keepalive_interval: u32) -> Self {
        Self {
            builder: self
                .builder
                .property("keepalive-interval", keepalive_interval),
        }
    }

    /// Timeout in seconds for when the absence of a pong from a keepalive
    /// ping is assumed to be caused by a faulty connection. The WebSocket
    /// will be transitioned to a closed state when this happens.
    ///
    /// If set to 0 then the absence of pongs from keepalive pings is
    /// ignored.
    #[cfg(feature = "v3_6")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
    pub fn keepalive_pong_timeout(self, keepalive_pong_timeout: u32) -> Self {
        Self {
            builder: self
                .builder
                .property("keepalive-pong-timeout", keepalive_pong_timeout),
        }
    }

    /// The maximum payload size for incoming packets.
    ///
    /// The protocol expects or 0 to not limit it.
    pub fn max_incoming_payload_size(self, max_incoming_payload_size: u64) -> Self {
        Self {
            builder: self
                .builder
                .property("max-incoming-payload-size", max_incoming_payload_size),
        }
    }

    /// The client's Origin.
    pub fn origin(self, origin: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("origin", origin.into()),
        }
    }

    /// The chosen protocol, or [`None`] if a protocol was not agreed
    /// upon.
    pub fn protocol(self, protocol: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("protocol", protocol.into()),
        }
    }

    /// The URI of the WebSocket.
    ///
    /// For servers this represents the address of the WebSocket,
    /// and for clients it is the address connected to.
    pub fn uri(self, uri: &glib::Uri) -> Self {
        Self {
            builder: self.builder.property("uri", uri.clone()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`WebsocketConnection`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> WebsocketConnection {
        self.builder.build()
    }
}