-
Notifications
You must be signed in to change notification settings - Fork 71
/
flow.h
59 lines (49 loc) · 2.13 KB
/
flow.h
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
/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef THIRD_PARTY_NEPER_FLOW_H
#define THIRD_PARTY_NEPER_FLOW_H
#include <stdbool.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/types.h>
struct flow; /* note: struct is defined opaquely within flow.c */
struct neper_stat;
struct thread;
typedef void (*flow_handler)(struct flow *, uint32_t);
/* Simple accessors. */
int flow_fd(const struct flow *);
int flow_id(const struct flow *);
void *flow_mbuf(const struct flow *);
void *flow_opaque(const struct flow *);
struct neper_stat *flow_stat(const struct flow *);
struct thread *flow_thread(const struct flow *);
int flow_postpone(struct flow *);
int flow_serve_pending(struct thread *t); /* process postponed events */
void flow_event(const struct epoll_event *); /* process one epoll event */
void flow_mod(struct flow *, flow_handler, uint32_t events, bool or_die);
void flow_reconnect(struct flow *, flow_handler, uint32_t events);
struct flow_create_args {
struct thread *thread; /* owner of this flow */
int fd; /* the associated fd for epoll */
uint32_t events; /* the epoll event mask */
void *opaque; /* state opaque to the calling layer */
flow_handler handler; /* state machine: initial callback */
void *(*mbuf_alloc)(struct thread *); /* allocates message buffer */
struct neper_stat *(*stat)(struct flow *); /* stats callback */
};
void flow_create(const struct flow_create_args *);
void flow_delete(struct flow *);
#endif