Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse http socket #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/wifi_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,13 @@ static void http_task(void *arg) {
INFO("Starting HTTP server");

struct sockaddr_in serv_addr;
int listenfd = socket(AF_INET, SOCK_STREAM, 0);
int listenfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
memset(&serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(WIFI_CONFIG_SERVER_PORT);
int flags;
int enable = 1;
if ((flags = lwip_fcntl(listenfd, F_GETFL, 0)) < 0) {
ERROR("Failed to get HTTP socket flags");
lwip_close(listenfd);
Expand All @@ -389,6 +390,11 @@ static void http_task(void *arg) {
vTaskDelete(NULL);
return;
}
if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) {
ERROR("Error in setsockopt");
lwip_close(listenfd);
return;
}
bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
listen(listenfd, 2);

Expand Down
2 changes: 1 addition & 1 deletion tools/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def gen_embedded(content):
def process_part(part):
return "\n".join(
"\"" + line.lstrip().replace('"', '\\"') + "\""
for line in part.split("\n")
for line in part.splitlines()
if line.strip()
)

Expand Down