#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ustream.h"
#include "uloop.h"
#include "usock.h"
Go to the source code of this file.
◆ client_close()
static void client_close |
( |
struct ustream * |
s | ) |
|
|
static |
Definition at line 52 of file ustream-example.c.
56 fprintf(stderr,
"Connection closed\n");
#define container_of(ptr, type, member)
void ustream_free(struct ustream *s)
◆ client_notify_state()
static void client_notify_state |
( |
struct ustream * |
s | ) |
|
|
static |
Definition at line 72 of file ustream-example.c.
79 fprintf(stderr,
"eof!, pending: %d, total: %d\n",
s->w.data_bytes, cl->
ctr);
static void client_close(struct ustream *s)
◆ client_notify_write()
static void client_notify_write |
( |
struct ustream * |
s, |
|
|
int |
bytes |
|
) |
| |
|
static |
Definition at line 62 of file ustream-example.c.
64 fprintf(stderr,
"Wrote %d bytes, pending: %d\n", bytes, s->
w.
data_bytes);
67 fprintf(stderr,
"Unblock read\n");
struct ustream_buf_list r w
void ustream_set_read_blocked(struct ustream *s, bool set)
static bool ustream_read_blocked(struct ustream *s)
◆ client_read_cb()
static void client_read_cb |
( |
struct ustream * |
s, |
|
|
int |
bytes |
|
) |
| |
|
static |
Definition at line 25 of file ustream-example.c.
36 newline = strchr(buf->
data,
'\n');
43 cl->
ctr += newline + 1 - str;
47 fprintf(stderr,
"Block read, bytes: %d\n", s->
w.
data_bytes);
int ustream_printf(struct ustream *s, const char *format,...)
void ustream_consume(struct ustream *s, int len)
char * ustream_get_read_buf(struct ustream *s, int *buflen)
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 133 of file ustream-example.c.
137 while ((ch = getopt(argc, argv,
"p:")) != -1) {
143 return usage(argv[0]);
static int run_server(void)
static int usage(const char *name)
◆ run_server()
static int run_server |
( |
void |
| ) |
|
|
static |
Definition at line 110 of file ustream-example.c.
int uloop_fd_add(struct uloop_fd *sock, unsigned int flags)
static int uloop_run(void)
int usock(int type, const char *host, const char *service)
static void server_cb(struct uloop_fd *fd, unsigned int events)
static struct uloop_fd server
◆ server_cb()
static void server_cb |
( |
struct uloop_fd * |
fd, |
|
|
unsigned int |
events |
|
) |
| |
|
static |
Definition at line 85 of file ustream-example.c.
88 unsigned int sl =
sizeof(
struct sockaddr_in);
95 sfd = accept(
server.
fd, (
struct sockaddr *) &cl->
sin, &sl);
97 fprintf(stderr,
"Accept failed\n");
107 fprintf(stderr,
"New connection\n");
void(* notify_write)(struct ustream *s, int bytes)
void(* notify_read)(struct ustream *s, int bytes_new)
void(* notify_state)(struct ustream *s)
static void client_read_cb(struct ustream *s, int bytes)
struct client * next_client
static void client_notify_state(struct ustream *s)
static void client_notify_write(struct ustream *s, int bytes)
void ustream_fd_init(struct ustream_fd *sf, int fd)
◆ usage()
static int usage |
( |
const char * |
name | ) |
|
|
static |
◆ next_client
struct client* next_client = NULL |
◆ port
const char* port = "10000" |
|
static |
◆ server