fix bug added with wrong continue

This commit is contained in:
Adam D. Ruppe 2023-08-16 10:04:02 -04:00
parent 7150cd81f4
commit 682ddd0563
1 changed files with 22 additions and 6 deletions

28
cgi.d
View File

@ -5838,12 +5838,12 @@ class ListeningConnectionManager {
void existing_connection_new_data() { void existing_connection_new_data() {
// wait until a slot opens up // wait until a slot opens up
//int waited = 0; // int waited = 0;
while(queueLength >= queue.length) { while(queueLength >= queue.length) {
Thread.sleep(1.msecs); Thread.sleep(1.msecs);
//waited ++; // waited ++;
} }
//if(waited) {import std.stdio; writeln(waited);} // if(waited) {import std.stdio; writeln(waited);}
synchronized(this) { synchronized(this) {
queue[nextIndexBack] = sn; queue[nextIndexBack] = sn;
nextIndexBack++; nextIndexBack++;
@ -6259,7 +6259,7 @@ class WorkerThread : Thread {
} }
foreach(listener; lcm.listeners) { foreach(listener; lcm.listeners) {
epoll_event ev; epoll_event ev;
ev.events = EPOLLIN | EPOLLEXCLUSIVE; // EPOLLEXCLUSIVE is only available on kernels since like 2017 but that's prolly good enough. ev.events = EPOLLIN | EPOLLEXCLUSIVE; // EPOLLEXCLUSIVE is only available on kernels since like 2017 but that's prolly good enough.
ev.data.fd = listener.handle; ev.data.fd = listener.handle;
if(epoll_ctl(epfd, EPOLL_CTL_ADD, listener.handle, &ev) == -1) if(epoll_ctl(epfd, EPOLL_CTL_ADD, listener.handle, &ev) == -1)
@ -6296,7 +6296,7 @@ class WorkerThread : Thread {
// might have beat us to it, but the wakeup event thundered our herds. // might have beat us to it, but the wakeup event thundered our herds.
try try
sn = listener.accept(); // don't need to do the acceptCancelable here since the epoll checks it better sn = listener.accept(); // don't need to do the acceptCancelable here since the epoll checks it better
catch(SocketAcceptException e) { continue; } catch(SocketAcceptException e) { continue outer; }
cloexec(sn); cloexec(sn);
if(lcm.tcp) { if(lcm.tcp) {
@ -6310,11 +6310,13 @@ class WorkerThread : Thread {
dg(sn); dg(sn);
continue outer; continue outer;
} else {
// writeln(events[idx].data.ptr);
} }
} }
if(cast(size_t) events[idx].data.ptr < 1024) { if(cast(size_t) events[idx].data.ptr < 1024) {
throw new Exception("this doesn't look like a fiber pointer..."); throw arsd.core.ArsdException!"this doesn't look like a fiber pointer... "(cast(size_t) events[idx].data.ptr);
} }
auto fiber = cast(CgiFiber) events[idx].data.ptr; auto fiber = cast(CgiFiber) events[idx].data.ptr;
fiber.proceed(); fiber.proceed();
@ -9921,10 +9923,24 @@ html", true, true);
case "html": case "html":
presentExceptionAsHtml(cgi, t, meta); presentExceptionAsHtml(cgi, t, meta);
break; break;
case "json":
presentExceptionAsJsonImpl(cgi, t);
break;
default: default:
} }
} }
private void presentExceptionAsJsonImpl()(Cgi cgi, Throwable t) {
cgi.setResponseStatus("500 Internal Server Error");
cgi.setResponseContentType("application/json");
import arsd.jsvar;
var v = var.emptyObject;
v.type = typeid(t).toString;
v.msg = t.msg;
v.fullString = t.toString();
cgi.write(v.toJson(), true);
}
/++ /++
If you override this, you will need to cast the exception type `t` dynamically, If you override this, you will need to cast the exception type `t` dynamically,