Commit 914606a0 authored by Sergey Lyubka's avatar Sergey Lyubka

fmtspool() -> mg_write()

parent b30417e9
...@@ -755,7 +755,6 @@ static int convert_uri_to_file_name(struct mg_connection *conn, char *buf, ...@@ -755,7 +755,6 @@ static int convert_uri_to_file_name(struct mg_connection *conn, char *buf,
return 0; return 0;
} }
#if 0
static int spool(struct iobuf *io, const void *buf, int len) { static int spool(struct iobuf *io, const void *buf, int len) {
char *ptr = io->buf; char *ptr = io->buf;
...@@ -770,7 +769,6 @@ static int spool(struct iobuf *io, const void *buf, int len) { ...@@ -770,7 +769,6 @@ static int spool(struct iobuf *io, const void *buf, int len) {
} }
return len; return len;
} }
#endif
static int vspool(struct iobuf *io, const char *fmt, va_list ap) { static int vspool(struct iobuf *io, const char *fmt, va_list ap) {
char *ptr = io->buf; char *ptr = io->buf;
...@@ -794,15 +792,19 @@ static int vspool(struct iobuf *io, const char *fmt, va_list ap) { ...@@ -794,15 +792,19 @@ static int vspool(struct iobuf *io, const char *fmt, va_list ap) {
return len; return len;
} }
static int fmtspool(struct iobuf *io, const char *fmt, ...) { int mg_printf(struct mg_connection *conn, const char *fmt, ...) {
va_list ap; va_list ap;
int ret; int ret;
va_start(ap, fmt); va_start(ap, fmt);
ret = vspool(io, fmt, ap); ret = vspool(&conn->remote_iobuf, fmt, ap);
va_end(ap); va_end(ap);
return ret; return ret;
} }
int mg_write(struct mg_connection *conn, const void *buf, int len) {
return spool(&conn->remote_iobuf, buf, len);
}
static int is_error(int n) { static int is_error(int n) {
return n == 0 || (n < 0 && errno != EINTR && errno != EAGAIN); return n == 0 || (n < 0 && errno != EINTR && errno != EAGAIN);
} }
...@@ -845,12 +847,12 @@ static void open_local_endpoint(struct mg_connection *conn) { ...@@ -845,12 +847,12 @@ static void open_local_endpoint(struct mg_connection *conn) {
exists = convert_uri_to_file_name(conn, path, sizeof(path), &st); exists = convert_uri_to_file_name(conn, path, sizeof(path), &st);
if (exists && (conn->endpoint.fd = open(path, O_RDONLY)) != -1) { if (exists && (conn->endpoint.fd = open(path, O_RDONLY)) != -1) {
fmtspool(&conn->remote_iobuf, "HTTP/1.0 200 OK\r\n" mg_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Length: %" INT64_FMT "\r\n" "\r\n", "Content-Length: %" INT64_FMT "\r\n" "\r\n",
(int64_t) st.st_size); (int64_t) st.st_size);
conn->endpoint_type = EP_FILE; conn->endpoint_type = EP_FILE;
} else { } else {
fmtspool(&conn->remote_iobuf, "%s", "HTTP/1.0 404 Not Found\r\n\r\n"); mg_printf(conn, "%s", "HTTP/1.0 404 Not Found\r\n\r\n");
conn->flags |= CONN_SPOOL_DONE; conn->flags |= CONN_SPOOL_DONE;
} }
} }
...@@ -1079,7 +1081,7 @@ struct mg_server *mg_create_server(const char *opts[], mg_event_handler_t func, ...@@ -1079,7 +1081,7 @@ struct mg_server *mg_create_server(const char *opts[], mg_event_handler_t func,
} }
static int event_handler(struct mg_event *ev) { static int event_handler(struct mg_event *ev) {
fmtspool(&ev->conn->remote_iobuf, "%s", "HTTP/1.0 200 OK\r\n\r\n:-)\n"); mg_printf(ev->conn, "%s", "HTTP/1.0 200 OK\r\n\r\n:-)\n");
return 1; return 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment