mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
Support parallel access device's web
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
@@ -68,8 +68,8 @@ static void on_net_read(struct ev_loop *loop, struct ev_io *w, int revents)
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
buffer_put_u8(wb, MSG_TYPE_WEB);
|
buffer_put_u8(wb, MSG_TYPE_WEB);
|
||||||
buffer_put_u16be(wb, 2 + ret);
|
buffer_put_u16be(wb, 18 + ret);
|
||||||
buffer_put_u16be(wb, ctx->port);
|
buffer_put_data(wb, ctx->addr, 18);
|
||||||
buffer_put_data(wb, buf, ret);
|
buffer_put_data(wb, buf, ret);
|
||||||
ev_io_start(rtty->loop, &rtty->iow);
|
ev_io_start(rtty->loop, &rtty->iow);
|
||||||
|
|
||||||
@@ -128,23 +128,26 @@ static void on_connected(int sock, void *arg)
|
|||||||
ctx->sock = sock;
|
ctx->sock = sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct web_request_ctx *find_exist_ctx(struct list_head *reqs, int port)
|
static struct web_request_ctx *find_exist_ctx(struct list_head *reqs, uint8_t *addr)
|
||||||
{
|
{
|
||||||
struct web_request_ctx *ctx;
|
struct web_request_ctx *ctx;
|
||||||
|
|
||||||
list_for_each_entry(ctx, reqs, head)
|
list_for_each_entry(ctx, reqs, head) {
|
||||||
if (ctx->port == port)
|
if (!memcmp(ctx->addr, addr, 18))
|
||||||
return ctx;
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void web_request(struct rtty *rtty, int len)
|
void web_request(struct rtty *rtty, int len)
|
||||||
{
|
{
|
||||||
struct web_request_ctx *ctx;
|
struct web_request_ctx *ctx;
|
||||||
int port, sock, req_len;
|
|
||||||
struct sockaddr_in addrin = {
|
struct sockaddr_in addrin = {
|
||||||
.sin_family = AF_INET
|
.sin_family = AF_INET
|
||||||
};
|
};
|
||||||
|
int sock, req_len;
|
||||||
|
uint8_t addr[18];
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
@@ -152,13 +155,14 @@ void web_request(struct rtty *rtty, int len)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
port = buffer_pull_u16be(&rtty->rb);
|
buffer_pull(&rtty->rb, addr, 18);
|
||||||
req_len = len - 2;
|
|
||||||
|
req_len = len - 18;
|
||||||
|
|
||||||
if (req_len == 0)
|
if (req_len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ctx = find_exist_ctx(&rtty->web_reqs, port);
|
ctx = find_exist_ctx(&rtty->web_reqs, addr);
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
buffer_pull(&rtty->rb, NULL, 6);
|
buffer_pull(&rtty->rb, NULL, 6);
|
||||||
req_len -= 6;
|
req_len -= 6;
|
||||||
@@ -178,9 +182,10 @@ void web_request(struct rtty *rtty, int len)
|
|||||||
|
|
||||||
ctx = (struct web_request_ctx *)calloc(1, sizeof(struct web_request_ctx));
|
ctx = (struct web_request_ctx *)calloc(1, sizeof(struct web_request_ctx));
|
||||||
ctx->rtty = rtty;
|
ctx->rtty = rtty;
|
||||||
ctx->port = port;
|
|
||||||
ctx->active = ev_now(rtty->loop);
|
ctx->active = ev_now(rtty->loop);
|
||||||
|
|
||||||
|
memcpy(ctx->addr, addr, 18);
|
||||||
|
|
||||||
data = buffer_put(&ctx->wb, req_len);
|
data = buffer_put(&ctx->wb, req_len);
|
||||||
buffer_pull(&rtty->rb, data, req_len);
|
buffer_pull(&rtty->rb, data, req_len);
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ struct web_request_ctx {
|
|||||||
struct buffer wb;
|
struct buffer wb;
|
||||||
ev_tstamp active;
|
ev_tstamp active;
|
||||||
int sock;
|
int sock;
|
||||||
int port;
|
uint8_t addr[18]; /* upstream connection address: [port ip] */
|
||||||
};
|
};
|
||||||
|
|
||||||
void web_request(struct rtty *rtty, int len);
|
void web_request(struct rtty *rtty, int len);
|
||||||
|
|||||||
Reference in New Issue
Block a user