zhangmeng
2024-04-22 16935f4aebffdd1b6580b844391a0aa0f4f3012b
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
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
 
#ifndef CORE_STREAM_H
#define CORE_STREAM_H
 
// This provides an abstraction for byte streams, allowing polymorphic
// use of them in rather flexible contexts.
 
#include "core/nng_impl.h"
 
// Private property operations (these include the types.)
extern int nni_stream_get(
    nng_stream *, const char *, void *, size_t *, nni_type);
extern int nni_stream_set(
    nng_stream *, const char *, const void *, size_t, nni_type);
 
extern int nni_stream_dialer_get(
    nng_stream_dialer *, const char *, void *, size_t *, nni_type);
extern int nni_stream_dialer_set(
    nng_stream_dialer *, const char *, const void *, size_t, nni_type);
 
extern int nni_stream_listener_get(
    nng_stream_listener *, const char *, void *, size_t *, nni_type);
extern int nni_stream_listener_set(
    nng_stream_listener *, const char *, const void *, size_t, nni_type);
 
// This is the common implementation of a connected byte stream.  It should be
// the first element of any implementation.  Applications are not permitted to
// access it directly.
struct nng_stream {
    void (*s_free)(void *);
    void (*s_close)(void *);
    void (*s_recv)(void *, nng_aio *);
    void (*s_send)(void *, nng_aio *);
    int (*s_get)(void *, const char *, void *, size_t *, nni_type);
    int (*s_set)(void *, const char *, const void *, size_t, nni_type);
};
 
// Dialer implementation.  Stream dialers create streams.
struct nng_stream_dialer {
    void (*sd_free)(void *);
    void (*sd_close)(void *);
    void (*sd_dial)(void *, nng_aio *);
    int (*sd_get)(void *, const char *, void *, size_t *, nni_type);
    int (*sd_set)(void *, const char *, const void *, size_t, nni_type);
};
 
// Listener implementation.  Stream listeners accept connections and create
// streams.
struct nng_stream_listener {
    void (*sl_free)(void *);
    void (*sl_close)(void *);
    int (*sl_listen)(void *);
    void (*sl_accept)(void *, nng_aio *);
    int (*sl_get)(void *, const char *, void *, size_t *, nni_type);
    int (*sl_set)(void *, const char *, const void *, size_t, nni_type);
};
 
#endif // CORE_STREAM_H