forked from google/neper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow.h
More file actions
79 lines (67 loc) · 2.8 KB
/
Copy pathflow.h
File metadata and controls
79 lines (67 loc) · 2.8 KB
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
/*
* 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>
#include <time.h>
struct flow; /* note: struct is defined opaquely within flow.c */
struct neper_stat;
struct thread;
struct rtt_log {
double rtt;
int thread_id;
int flow_id;
struct timespec timestamp;
};
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 *);
bool flow_serve_pending(
struct thread *t,
struct timespec *timeout); /* 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 */
};
struct flow *flow_create(const struct flow_create_args *);
long flow_rtt_log_count(const struct flow *f);
void flow_increment_rtt_log_count(struct flow *f);
void flow_delete(struct flow *);
/* Adds duration to f's next event time. */
void flow_update_next_event(struct flow *f, uint64_t duration);
/* Initialize RX zerocopy state for a flow. */
void flow_init_rx_zerocopy(struct flow *f, int buffer_size,
struct callbacks *cb);
/* Perform a zerocopy receive. */
ssize_t flow_recv_zerocopy(struct flow *f, void *copybuf, size_t copybuf_len);
#endif