From c32fd1e7a16b5a6234693a31dc92cbd274d97066 Mon Sep 17 00:00:00 2001 From: KyoungSoo Park Date: Mon, 18 Jun 2007 20:57:32 +0000 Subject: [PATCH] check into the head --- codemux.c | 51 ++++++++------------------------------------------- codemux.spec | 2 +- 2 files changed, 9 insertions(+), 44 deletions(-) diff --git a/codemux.c b/codemux.c index 34ffc30..3ca9ba0 100644 --- a/codemux.c +++ b/codemux.c @@ -15,14 +15,6 @@ #include #include "codemuxlib.h" -#define DEBUG 0 - -#ifdef DEBUG -#define TRACE(fmt, msg...) fprintf(stderr, "[%s,%d] " fmt, __FUNCTION__, __LINE__, ##msg) -#else -#define TRACE(fmt, msg...) (void)0 -#endif - #define CONF_FILE "/etc/codemux/codemux.conf" #define DEMUX_PORT 80 #define PIDFILE "/var/run/codemux.pid" @@ -39,8 +31,6 @@ among them */ #define FAIRNESS_CUTOFF (MAX_CONNS * 0.85) -/* codemux version */ -#define CODEMUX_VERSION "0.3" typedef struct FlowBuf { int fb_refs; /* num refs */ @@ -117,10 +107,8 @@ DumpStatus(int fd) int len; sprintf(start, - "CoDemux version %s\n" "numForks %d, numActiveSlices %d, numTotalSliceConns %d\n" "numNeedingHeaders %d, anySliceXidsNeeded %d\n", - CODEMUX_VERSION, numForks, numActiveSlices, numTotalSliceConns, numNeedingHeaders, anySliceXidsNeeded); start += strlen(start); @@ -657,10 +645,6 @@ ReallyCloseSocks(void) SliceConnsDec(sockInfo[fd].si_whichService); sockInfo[fd].si_whichService = -1; } - /* KyoungSoo*/ - if (sockInfo[fd].si_peerFd >= 0) { - sockInfo[sockInfo[fd].si_peerFd].si_peerFd = -1; - } } numSocksToClose = 0; } @@ -692,7 +676,7 @@ SocketReadyToRead(int fd) fb->fb_buf = malloc(FB_ALLOCSIZE); /* determine read buffer size - if 0, then block reads and return */ - if ((spaceLeft = FB_SIZE - fb->fb_used) <= 0) { + if ((spaceLeft = FB_SIZE - fb->fb_used) < 0) { if (si->si_needsHeaderSince) { write(fd, err400BadRequest, strlen(err400BadRequest)); CloseSock(fd); @@ -702,8 +686,8 @@ SocketReadyToRead(int fd) ClearFd(fd, &masterReadSet); return; } - } - + } + /* read as much as allowed, and is available */ if ((res = read(fd, &fb->fb_buf[fb->fb_used], spaceLeft)) == 0) { CloseSock(fd); @@ -716,7 +700,6 @@ SocketReadyToRead(int fd) if (res == -1) { if (errno == EAGAIN) return; - TRACE("fd=%d errno=%d errstr=%s\n",fd, errno, strerror(errno)); CloseSock(fd); if (fb->fb_used == 0 && si->si_peerFd >= 0) { CloseSock(si->si_peerFd); @@ -726,7 +709,7 @@ SocketReadyToRead(int fd) } fb->fb_used += res; fb->fb_buf[fb->fb_used] = 0; /* terminate it for convenience */ - // printf("sock %d, read %d, total %d\n", fd, res, fb->fb_used); + printf("sock %d, read %d, total %d\n", fd, res, fb->fb_used); /* if we need header, check if we've gotten it. if so, do modifications and continue. if not, check if we've read the @@ -755,7 +738,6 @@ SocketReadyToRead(int fd) (numTotalSliceConns > FAIRNESS_CUTOFF && slice->si_numConns > MAX_CONNS/numActiveSlices)) { write(fd, err503TooBusy, strlen(err503TooBusy)); - TRACE("CloseSock(): fd=%d too busy\n", fd); CloseSock(fd); return; } @@ -776,7 +758,6 @@ SocketReadyToRead(int fd) numNeedingHeaders--; if (StartConnect(fd, whichService) != SUCCESS) { write(fd, err503Unavailable, strlen(err503Unavailable)); - TRACE("CloseSock(): fd=%d StartConnect() failed\n", fd); CloseSock(fd); return; } @@ -786,13 +767,9 @@ SocketReadyToRead(int fd) /* write anything possible */ if (WriteAvailData(si->si_peerFd) != SUCCESS) { /* assume the worst and close */ - TRACE("CloseSock(): fd=%d WriteAvailData() failed errno=%d errstr=%s\n", - fd, errno, strerror(errno)); CloseSock(fd); - if (si->si_peerFd >=0) { - CloseSock(si->si_peerFd); - si->si_peerFd = -1; - } + CloseSock(si->si_peerFd); + si->si_peerFd = -1; } } /*-----------------------------------------------------------------*/ @@ -813,8 +790,6 @@ SocketReadyToWrite(int fd) /* if we have data, write it */ if (WriteAvailData(fd) != SUCCESS) { /* assume the worst and close */ - TRACE("CloseSock(): fd=%d WriteAvailData() failed errno=%d errstr=%s\n", - fd, errno, strerror(errno)); CloseSock(fd); if (si->si_peerFd >= 0) { CloseSock(si->si_peerFd); @@ -824,9 +799,8 @@ SocketReadyToWrite(int fd) } /* if peer is closed and we're done writing, we should close */ - if (si->si_peerFd < 0 && si->si_writeBuf->fb_used == 0) { + if (si->si_peerFd < 0 && si->si_writeBuf->fb_used == 0) CloseSock(fd); - } } /*-----------------------------------------------------------------*/ static void @@ -862,7 +836,7 @@ CloseReqlessConns(void) /* if it's too old, close it */ for (i = 0; i < highestSetFd+1; i++) { if (sockInfo[i].si_needsHeaderSince && - (now - sockInfo[i].si_needsHeaderSince) > maxAge) + (now - sockInfo[i].si_needsHeaderSince) > maxAge) CloseSock(i); } } @@ -936,11 +910,6 @@ MainLoop(int lisSock) socklen_t lenAddr = sizeof(addr); if ((newSock = accept(lisSock, (struct sockaddr *) &addr, &lenAddr)) >= 0) { - /* make socket non-blocking */ - if (fcntl(newSock, F_SETFL, O_NONBLOCK) < 0) { - close(newSock); - continue; - } memset(&sockInfo[newSock], 0, sizeof(SockInfo)); sockInfo[newSock].si_needsHeaderSince = now; numNeedingHeaders++; @@ -1056,10 +1025,6 @@ main(int argc, char *argv[]) /* open the log file */ logFd = OpenLogFile(); - - /* write down the version */ - fprintf(stderr, "CoDemux version %s started\n", CODEMUX_VERSION); - while (1) { numForks++; if (fork()) { diff --git a/codemux.spec b/codemux.spec index 50508e4..127e522 100644 --- a/codemux.spec +++ b/codemux.spec @@ -1,6 +1,6 @@ %define name codemux %define version 0.1 -%define release 6%{?pldistro:.%{pldistro}}%{?date:.%{date}} +%define release 5%{?pldistro:.%{pldistro}}%{?date:.%{date}} Summary: CoDemux - HTTP port DeMux Name: %{name} -- 2.43.0