Merge branch 'master' into next
[sliver-openvswitch.git] / lib / stream.h
1 /*
2  * Copyright (c) 2009 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
24 struct pstream;
25 struct stream;
26
27 void stream_usage(const char *name, bool active, bool passive, bool bootstrap);
28
29 /* Bidirectional byte streams. */
30 int stream_open(const char *name, struct stream **);
31 int stream_open_block(const char *name, struct stream **);
32 void stream_close(struct stream *);
33 const char *stream_get_name(const struct stream *);
34 uint32_t stream_get_remote_ip(const struct stream *);
35 uint16_t stream_get_remote_port(const struct stream *);
36 uint32_t stream_get_local_ip(const struct stream *);
37 uint16_t stream_get_local_port(const struct stream *);
38 int stream_connect(struct stream *);
39 int stream_recv(struct stream *, void *buffer, size_t n);
40 int stream_send(struct stream *, const void *buffer, size_t n);
41
42 void stream_run(struct stream *);
43 void stream_run_wait(struct stream *);
44
45 enum stream_wait_type {
46     STREAM_CONNECT,
47     STREAM_RECV,
48     STREAM_SEND
49 };
50 void stream_wait(struct stream *, enum stream_wait_type);
51 void stream_connect_wait(struct stream *);
52 void stream_recv_wait(struct stream *);
53 void stream_send_wait(struct stream *);
54
55 /* Passive streams: listeners for incoming stream connections. */
56 int pstream_open(const char *name, struct pstream **);
57 const char *pstream_get_name(const struct pstream *);
58 void pstream_close(struct pstream *);
59 int pstream_accept(struct pstream *, struct stream **);
60 int pstream_accept_block(struct pstream *, struct stream **);
61 void pstream_wait(struct pstream *);
62
63 #endif /* stream.h */