Prepare Open vSwitch 1.1.2 release.
[sliver-openvswitch.git] / lib / stream.h
1 /*
2  * Copyright (c) 2009, 2010, 2011 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef STREAM_H
18 #define STREAM_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <sys/types.h>
24 #include "openvswitch/types.h"
25 #include "vlog.h"
26
27 struct pstream;
28 struct stream;
29
30 void stream_usage(const char *name, bool active, bool passive, bool bootstrap);
31
32 /* Bidirectional byte streams. */
33 int stream_verify_name(const char *name);
34 int stream_open(const char *name, struct stream **);
35 int stream_open_block(int error, struct stream **);
36 void stream_close(struct stream *);
37 const char *stream_get_name(const struct stream *);
38 ovs_be32 stream_get_remote_ip(const struct stream *);
39 ovs_be16 stream_get_remote_port(const struct stream *);
40 ovs_be32 stream_get_local_ip(const struct stream *);
41 ovs_be16 stream_get_local_port(const struct stream *);
42 int stream_connect(struct stream *);
43 int stream_recv(struct stream *, void *buffer, size_t n);
44 int stream_send(struct stream *, const void *buffer, size_t n);
45
46 void stream_run(struct stream *);
47 void stream_run_wait(struct stream *);
48
49 enum stream_wait_type {
50     STREAM_CONNECT,
51     STREAM_RECV,
52     STREAM_SEND
53 };
54 void stream_wait(struct stream *, enum stream_wait_type);
55 void stream_connect_wait(struct stream *);
56 void stream_recv_wait(struct stream *);
57 void stream_send_wait(struct stream *);
58
59 /* Passive streams: listeners for incoming stream connections. */
60 int pstream_verify_name(const char *name);
61 int pstream_open(const char *name, struct pstream **);
62 const char *pstream_get_name(const struct pstream *);
63 void pstream_close(struct pstream *);
64 int pstream_accept(struct pstream *, struct stream **);
65 int pstream_accept_block(struct pstream *, struct stream **);
66 void pstream_wait(struct pstream *);
67 \f
68 /* Convenience functions. */
69
70 int stream_open_with_default_ports(const char *name,
71                                    uint16_t default_tcp_port,
72                                    uint16_t default_ssl_port,
73                                    struct stream **);
74 int pstream_open_with_default_ports(const char *name,
75                                     uint16_t default_ptcp_port,
76                                     uint16_t default_pssl_port,
77                                     struct pstream **);
78 \f
79 /* Error reporting. */
80
81 enum stream_content_type {
82     STREAM_UNKNOWN,
83     STREAM_OPENFLOW,
84     STREAM_SSL,
85     STREAM_JSONRPC
86 };
87
88 void stream_report_content(const void *, ssize_t, enum stream_content_type,
89                            struct vlog_module *, const char *stream_name);
90
91 #endif /* stream.h */