1 #include <sys/socket.h>
2 #include <netinet/in.h>
15 static const char *
port =
"10000";
19 struct sockaddr_in
sin;
36 newline = strchr(buf->
data,
'\n');
43 cl->
ctr += newline + 1 - str;
47 fprintf(stderr,
"Block read, bytes: %d\n", s->
w.
data_bytes);
56 fprintf(stderr,
"Connection closed\n");
64 fprintf(stderr,
"Wrote %d bytes, pending: %d\n", bytes,
s->w.data_bytes);
67 fprintf(stderr,
"Unblock read\n");
79 fprintf(stderr,
"eof!, pending: %d, total: %d\n",
s->w.data_bytes, cl->
ctr);
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");
129 fprintf(stderr,
"Usage: %s -p <port>\n",
name);
133 int main(
int argc,
char **argv)
137 while ((ch = getopt(argc, argv,
"p:")) != -1) {
143 return usage(argv[0]);
#define container_of(ptr, type, member)
struct ustream_buf_list r w
void(* notify_write)(struct ustream *s, int bytes)
void(* notify_read)(struct ustream *s, int bytes_new)
void(* notify_state)(struct ustream *s)
static struct epoll_event events[ULOOP_MAX_EVENTS]
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 client_read_cb(struct ustream *s, int bytes)
static void server_cb(struct uloop_fd *fd, unsigned int events)
int main(int argc, char **argv)
static void client_close(struct ustream *s)
struct client * next_client
static void client_notify_state(struct ustream *s)
static struct uloop_fd server
static void client_notify_write(struct ustream *s, int bytes)
static int run_server(void)
static int usage(const char *name)
void ustream_fd_init(struct ustream_fd *sf, int fd)
void ustream_free(struct ustream *s)
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)
void ustream_set_read_blocked(struct ustream *s, bool set)
static bool ustream_read_blocked(struct ustream *s)