- yaz_log (LOG_DEBUG, "ir_session (accept)");
- if (!cs_accept (conn))
- {
- yaz_log (LOG_LOG, "accept failed");
- destroy_association(assoc);
- iochan_destroy(h);
- }
- iochan_clearflag (h, EVENT_OUTPUT|EVENT_OUTPUT);
- if (conn->io_pending)
- { /* cs_accept didn't complete */
- assoc->cs_accept_mask =
- ((conn->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) |
- ((conn->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0);
-
- iochan_setflag (h, assoc->cs_accept_mask);
- }
- else
- { /* cs_accept completed. Prepare for reading (cs_get) */
- assoc->cs_accept_mask = 0;
- assoc->cs_get_mask = EVENT_INPUT;
- iochan_setflag (h, assoc->cs_get_mask);
- }
- return;
- }
- if ((event & assoc->cs_get_mask) || (event & EVENT_WORK)) /* input */
- {
- if ((assoc->cs_put_mask & EVENT_INPUT) == 0 && (event & assoc->cs_get_mask))
- {
- yaz_log(LOG_DEBUG, "ir_session (input)");
- /* We aren't speaking to this fellow */
- if (assoc->state == ASSOC_DEAD)
- {
- yaz_log(LOG_LOG, "Connection closed - end of session");
- cs_close(conn);
- destroy_association(assoc);
- iochan_destroy(h);
- return;
- }
- assoc->cs_get_mask = EVENT_INPUT;
- if ((res = cs_get(conn, &assoc->input_buffer,
- &assoc->input_buffer_len)) <= 0)
- {
- yaz_log(LOG_LOG, "Connection closed by client");
- cs_close(conn);
- destroy_association(assoc);
- iochan_destroy(h);
- return;
- }
- else if (res == 1) /* incomplete read - wait for more */
- {
- if (conn->io_pending & CS_WANT_WRITE)
- assoc->cs_get_mask |= EVENT_OUTPUT;
- iochan_setflag(h, assoc->cs_get_mask);
- return;
- }
- if (cs_more(conn)) /* more stuff - call us again later, please */
- iochan_setevent(h, EVENT_INPUT);
-
- /* we got a complete PDU. Let's decode it */
- yaz_log(LOG_DEBUG, "Got PDU, %d bytes: lead=%02X %02X %02X", res,
- assoc->input_buffer[0] & 0xff,
- assoc->input_buffer[1] & 0xff,
- assoc->input_buffer[2] & 0xff);
- req = request_get(&assoc->incoming); /* get a new request */
- odr_reset(assoc->decode);
- odr_setbuf(assoc->decode, assoc->input_buffer, res, 0);
- if (!z_GDU(assoc->decode, &req->gdu_request, 0, 0))
- {
- yaz_log(LOG_LOG, "ODR error on incoming PDU: %s [element %s] "
- "[near byte %d] ",
- odr_errmsg(odr_geterror(assoc->decode)),
- odr_getelement(assoc->decode),
- odr_offset(assoc->decode));
- if (assoc->decode->error != OHTTP)
- {
- yaz_log(LOG_LOG, "PDU dump:");
- odr_dumpBER(yaz_log_file(), assoc->input_buffer, res);
- request_release(req);
- do_close(assoc, Z_Close_protocolError,"Malformed package");
- }
- else
- {
- Z_GDU *p = z_get_HTTP_Response(assoc->encode, 400);
- assoc->state = ASSOC_DEAD;
- process_gdu_response(assoc, req, p);
- }
- return;
- }
- req->request_mem = odr_extract_mem(assoc->decode);
- if (assoc->print)
- {
- if (!z_GDU(assoc->print, &req->gdu_request, 0, 0))
- yaz_log(LOG_WARN, "ODR print error: %s",
- odr_errmsg(odr_geterror(assoc->print)));
- odr_reset(assoc->print);
- }
- request_enq(&assoc->incoming, req);
- }
-
- /* can we do something yet? */
- req = request_head(&assoc->incoming);
- if (req->state == REQUEST_IDLE)
- {
- request_deq(&assoc->incoming);
- process_gdu_request(assoc, req);
- }
+ if (!cs_accept (conn))
+ {
+ yaz_log (YLOG_WARN, "accept failed");
+ destroy_association(assoc);
+ iochan_destroy(h);
+ }
+ iochan_clearflag (h, EVENT_OUTPUT);
+ if (conn->io_pending)
+ { /* cs_accept didn't complete */
+ assoc->cs_accept_mask =
+ ((conn->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) |
+ ((conn->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0);
+
+ iochan_setflag (h, assoc->cs_accept_mask);
+ }
+ else
+ { /* cs_accept completed. Prepare for reading (cs_get) */
+ assoc->cs_accept_mask = 0;
+ assoc->cs_get_mask = EVENT_INPUT;
+ iochan_setflag (h, assoc->cs_get_mask);
+ }
+ return;
+ }
+ if (event & assoc->cs_get_mask) /* input */
+ {
+ if (!ir_read(h, event))
+ return;
+ req = request_head(&assoc->incoming);
+ if (req->state == REQUEST_IDLE)
+ {
+ request_deq(&assoc->incoming);
+ process_gdu_request(assoc, req);
+ }