Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
8700faf2
Commit
8700faf2
authored
Oct 21, 2013
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io: add io_conn_fd()
Useful for getsockname(). Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
e40f5c50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
ccan/io/io.c
ccan/io/io.c
+5
-0
ccan/io/io.h
ccan/io/io.h
+8
-0
ccan/io/test/run-01-start-finish.c
ccan/io/test/run-01-start-finish.c
+4
-1
No files found.
ccan/io/io.c
View file @
8700faf2
...
...
@@ -472,6 +472,11 @@ struct io_plan io_break_(void *ret, struct io_plan plan)
return
plan
;
}
int
io_conn_fd
(
const
struct
io_conn
*
conn
)
{
return
conn
->
fd
.
fd
;
}
void
io_set_alloc
(
void
*
(
*
allocfn
)(
size_t
size
),
void
*
(
*
reallocfn
)(
void
*
ptr
,
size_t
size
),
void
(
*
freefn
)(
void
*
ptr
))
...
...
ccan/io/io.h
View file @
8700faf2
...
...
@@ -491,6 +491,14 @@ struct io_plan io_close_cb(struct io_conn *, void *unused);
*/
void
*
io_loop
(
void
);
/**
* io_conn_fd - get the fd from a connection.
* @conn: the connection.
*
* Sometimes useful, eg for getsockname().
*/
int
io_conn_fd
(
const
struct
io_conn
*
conn
);
/**
* io_set_alloc - set alloc/realloc/free function for io to use.
* @allocfn: allocator function
...
...
ccan/io/test/run-01-start-finish.c
View file @
8700faf2
...
...
@@ -9,10 +9,12 @@
#ifndef PORT
#define PORT "65001"
#endif
static
int
expected_fd
;
static
void
finish_ok
(
struct
io_conn
*
conn
,
int
*
state
)
{
ok1
(
*
state
==
1
);
ok1
(
io_conn_fd
(
conn
)
==
expected_fd
);
(
*
state
)
++
;
io_break
(
state
+
1
,
io_idle
());
}
...
...
@@ -21,6 +23,7 @@ static void init_conn(int fd, int *state)
{
ok1
(
*
state
==
0
);
(
*
state
)
++
;
expected_fd
=
fd
;
io_set_finish
(
io_new_conn
(
fd
,
io_close
()),
finish_ok
,
state
);
}
...
...
@@ -64,7 +67,7 @@ int main(void)
int
fd
;
/* This is how many tests you plan to run */
plan_tests
(
9
);
plan_tests
(
10
);
fd
=
make_listen_fd
(
PORT
,
&
addrinfo
);
ok1
(
fd
>=
0
);
l
=
io_new_listener
(
fd
,
init_conn
,
&
state
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment