亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serverthread.java

?? 純java服務器
?? JAVA
字號:
// $Id: ServerThread.java,v 1.42 2001/01/23 03:08:28 nconway Exp $
package tornado;
import java.net.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Date;

public class ServerThread extends Thread {
    private final static int READ_BLOCK = 8192;

    // per-client resources: these are recreated for every connection
    private Request request;
    private Response response;
    /** The file asked for by the client, if appropriate.*/
    private File requestFile;
    /** The message in the access log for this request.*/
    private CommonLogMessage accessLog;

    // per-server resources: these are created once per ServerThread
    private final ArrayList taskPool;
    private final ServerPool serverPool;

    /** Constructs a new ServerThread using the specified values. This should
      * only rarely be called directly: for most purposes, you should spawn
      * new threads using {@link tornado.ServerPool#addThread()}.
      */
    ServerThread(ThreadGroup group, ArrayList tPool, ServerPool sPool) {
        super(group, "");
        taskPool = tPool;
        serverPool = sPool;
    }

    /** Begins an infinite loop waiting for connections and serving them.*/
    public void run() {
        Socket socket;
        while (true) {
            synchronized (taskPool) {
                /* Wait until we find an incoming connection. If
                 * pool is non-empty, there is already a connection
                 * waiting to be processed, so we can skip the wait().*/
                while (taskPool.isEmpty()) {
                    try {
                        taskPool.wait();
                    } catch (InterruptedException e) {
                        /* We were interrupted by another thread. In the
                         * current design, this means the ServerPool wants
                         * us to die.*/
                        return;
                    }
                }
                // finally, we have an incoming connection
                socket = (Socket)taskPool.remove(0);
            }

            // start the HTTP transaction with the client
            try {
                request = new Request(socket);
                response = new Response(request);
                accessLog = new CommonLogMessage(request);
                handOffRequest();
            } catch (HTTPException e) {
                // we got a protocol error of some kind - expected
                sendErrorPage(e);
            } catch (Exception e) {
                // we got a more serious error - these should not occur
                e.printStackTrace();
            } finally {
                Tornado.log.logAccess(accessLog);
                finishConnection();
            }
        }
    }

    /** Decides what to do with a connection. This looks at the HTTP
      * headers sent by the client, sends error pages as necessary, and
      * then decides which method to use to actually handle this request.
      */
    private void handOffRequest() throws HTTPException {
        String method = request.getType();

        if (method == null) {
            return;
        } else if (method.equals("GET")) {
            handleGetRequest();
        } else if (method.equals("HEAD")) {
            handleHeadRequest();
        } else if (method.equals("POST")) {
            handlePostRequest();
        } else if (method.equals("PUT")) {
            handlePutRequest();
        } else if (method.equals("OPTIONS")) {
            handleOptionsRequest();
        } else if (method.equals("DELETE")) {
            handleDeleteRequest();
        } else if (method.equals("TRACE")) {
            handleTraceRequest();
        } else if (method.equals("CONNECT")) {
            handleConnectRequest();
        } else {
            throw new HTTPException(HTTP.NOT_IMPLEMENTED);
        }
    }

    /** Handles an HTTP GET request from the client.*/
    private void handleGetRequest() throws HTTPException {
        describeFile();
        try {
            response.finishHeaders();
            FileInputStream file = new FileInputStream(requestFile);
            /* Read and send file in blocks.*/
            byte[] fileData = new byte[READ_BLOCK];
            for (int i=0; i<requestFile.length(); i+=READ_BLOCK) {
                int bytesRead = file.read(fileData);
                response.rawOut.write(fileData, 0, bytesRead);
            }
            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /** Handles an HTTP HEAD request from the client.*/
    private void handleHeadRequest() throws HTTPException {
        describeFile();
        try {
            response.finishHeaders();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /** Handles an HTTP POST request from the client. Not
      * implemented yet.
      */
    private void handlePostRequest() throws HTTPException {
        throw new HTTPException(HTTP.NOT_IMPLEMENTED);
    }

    /** Handles an HTTP PUT request from the client. Not
      * implemented yet.
      */
    private void handlePutRequest() throws HTTPException {
        throw new HTTPException(HTTP.NOT_IMPLEMENTED);
    }

    /** Handles an HTTP OPTIONS request from the client. Not
      * implemented yet.
      */
    private void handleOptionsRequest() throws HTTPException {
        throw new HTTPException(HTTP.NOT_IMPLEMENTED);
    }

    /** Handles an HTTP DELETE request from the client. Not
      * implemented yet.
      */
    private void handleDeleteRequest() throws HTTPException {
        throw new HTTPException(HTTP.NOT_IMPLEMENTED);
    }

    /** Handles an HTTP TRACE request from the client.*/
    private void handleTraceRequest() throws HTTPException {
        try {
            sendStatus(HTTP.OK);
            sendBasicHeaders();
            response.sendHeader("Content-Type: message/http");
            response.finishHeaders();
            // echo the client's request back to them
            response.out.write(request.getRawRequest());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /** Handles an HTTP CONNECT request from the client. Not
      * implemented yet.
      */
    private void handleConnectRequest() throws HTTPException {
        throw new HTTPException(HTTP.NOT_IMPLEMENTED);
    }

    /** Sends the headers about the URI the client asked for. This method
      * does the "legwork" when dealing with files: it takes the URI from
      * the client, uses {@link #translateURI(String)} to get a
      * <code>File</code>, checks for errors, and then sends the
      * relevant headers to the client about the specified URI. It is
      * used by both the HTTP GET and HEAD methods.
      */
    private void describeFile() throws HTTPException {
        requestFile = translateURI(request.getURI());

        if (requestFile.exists() == false)
            throw new HTTPException(HTTP.NOT_FOUND);

        if (requestFile.canRead() == false)
            throw new HTTPException(HTTP.FORBIDDEN);

        try {
            sendStatus(HTTP.OK);
            sendBasicHeaders();
            response.sendHeader("Content-Length: " + requestFile.length());
            response.sendHeader("Last-Modified: " + HTTP.formatDate(
                                        new Date(requestFile.lastModified())));
            response.sendHeader("Content-Type: " +
                Tornado.mime.getContentType(requestFile));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /** Concludes the work with the client and informs the ServerPool.*/
    private void finishConnection() {
        if (response != null) {
            try {
                response.finishResponse();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        serverPool.decrementBusyThreads();
    }

    /** Sends the specified HTTP error code page to the client.*/
    private void sendErrorPage(HTTPException httpE) {
        try {
            sendStatus(httpE.getCode());
            sendBasicHeaders();
            response.sendHeader("Content-Type: text/html");
            response.finishHeaders();
            response.out.write(httpE.getErrorPage());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /** Sends the specified HTTP status code to the client. This is just
      * a simple wrapper over {@link tornado.Response#sendStatus(int)},
      * with one additional function: it notes the status code in the access
      * log before sending it.
      */
    private void sendStatus(int statusCode) throws IOException {
        accessLog.setStatusCode(statusCode);
        response.sendStatus(statusCode);
    }

    /** Sends the HTTP headers to the client that are always sent. These
      * headers are those used in common by all HTTP responses.
      */
    private void sendBasicHeaders() throws IOException {
        response.sendHeader("Date: " + HTTP.formatDate(new Date()));
        response.sendHeader("Server: " + Tornado.config.getVersionSig());
        response.sendHeader("Connection: close");
    }

    /** Translates the URI to a filename. This takes an <b>absolute</b>
      * URI, performs some security checks, and translates this URI into
      * the designated file on the local filesystem. It then returns this
      * file.
      */
    private File translateURI(String uri) throws HTTPException {
        String relURI = uri.substring(uri.indexOf('/', 7));
        if (uri.indexOf("..", 1) != -1) {
            throw new HTTPException(HTTP.NOT_FOUND);
        }
        return new File(Tornado.config.getDocumentRoot() + relURI);
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天堂精品中文字幕在线| 激情文学综合插| 久久精品国内一区二区三区| 成人综合婷婷国产精品久久蜜臀| 欧美性xxxxxxxx| 国产精品天美传媒| 视频一区欧美日韩| 91福利在线观看| 国产精品久久久久永久免费观看| 久久精品国产一区二区| 欧美日韩1234| 亚洲一卡二卡三卡四卡| 色综合久久综合中文综合网| 久久久久久久久久久久久久久99| 日韩中文字幕1| 欧美在线视频全部完| 亚洲欧洲av一区二区三区久久| 老司机免费视频一区二区三区| 国产精品久久99| 一个色综合网站| 欧美日韩亚洲国产综合| 777a∨成人精品桃花网| 亚洲最新视频在线观看| 99久久免费视频.com| 欧美激情中文字幕一区二区| 国产福利一区二区三区视频在线 | 91麻豆免费观看| 中文字幕精品一区二区三区精品| 精品一区二区三区在线视频| 337p亚洲精品色噜噜噜| 丝袜美腿亚洲一区二区图片| 欧美日韩国产一级片| 亚洲国产成人精品视频| 欧美视频自拍偷拍| 五月天欧美精品| 7777精品伊人久久久大香线蕉的 | 欧美国产日韩精品免费观看| 国产精品99久久不卡二区| 久久亚洲私人国产精品va媚药| 精品一区二区三区蜜桃| 久久久久久久久岛国免费| 国产1区2区3区精品美女| 国产精品久久久久aaaa| 91同城在线观看| 亚洲国产欧美日韩另类综合 | 精品乱人伦小说| 麻豆成人免费电影| 久久精品人人爽人人爽| 成人精品视频网站| 一区二区不卡在线播放| 在线播放一区二区三区| 另类综合日韩欧美亚洲| 欧美国产一区视频在线观看| 一本久道久久综合中文字幕 | 成人国产精品视频| 一区二区三区四区国产精品| 欧美日韩精品二区第二页| 加勒比av一区二区| 亚洲桃色在线一区| 日韩免费性生活视频播放| 豆国产96在线|亚洲| 亚洲免费色视频| 日韩视频免费观看高清在线视频| 国产精品资源站在线| 亚洲男人天堂av网| 精品国产髙清在线看国产毛片| 成人av电影在线网| 日韩国产欧美一区二区三区| 久久久久久一二三区| 在线视频你懂得一区二区三区| 蜜桃av一区二区在线观看| 国产精品免费丝袜| 欧美一区二区性放荡片| 成av人片一区二区| 强制捆绑调教一区二区| 1区2区3区国产精品| 日韩色在线观看| 色88888久久久久久影院按摩| 麻豆成人在线观看| 亚洲国产成人91porn| 久久久.com| 91精品国产麻豆国产自产在线| 丁香啪啪综合成人亚洲小说| 日本不卡视频一二三区| 亚洲免费电影在线| 欧美激情一区二区三区不卡| 4438亚洲最大| 欧洲精品一区二区| 成人免费黄色在线| 国产综合久久久久久久久久久久| 亚洲在线免费播放| 中文字幕中文字幕一区二区| 精品国产第一区二区三区观看体验 | 久久伊99综合婷婷久久伊| 欧美男男青年gay1069videost| av网站一区二区三区| 国产毛片精品视频| 蜜臀av一级做a爰片久久| 午夜精品一区二区三区三上悠亚| 成人免费在线播放视频| 国产欧美一区二区精品婷婷 | 欧美日韩免费观看一区三区| 99久久精品国产一区二区三区 | 国产精品久久99| 国产日产欧产精品推荐色| 日韩精品一区在线观看| 6080午夜不卡| 在线不卡一区二区| 欧美群妇大交群的观看方式| 欧美日韩视频在线第一区| 在线观看一区二区精品视频| 一本大道久久a久久精品综合| 99久久免费精品| 91视频在线看| 色吧成人激情小说| 91国偷自产一区二区三区观看| 91在线播放网址| 91美女片黄在线| 欧洲激情一区二区| 成人高清视频在线观看| 日韩在线卡一卡二| 青青草成人在线观看| 黄色小说综合网站| 欧美日免费三级在线| 国产凹凸在线观看一区二区| 国产伦精品一区二区三区免费| 国产一区二三区好的| 国产福利一区二区| 粗大黑人巨茎大战欧美成人| aa级大片欧美| 在线免费亚洲电影| 欧美一区二区三区四区五区 | 欧美日韩精品免费观看视频| 欧美日韩一区二区三区四区五区| 欧美日韩国产小视频在线观看| 欧美一区二区在线免费播放| 久久久国际精品| 亚洲青青青在线视频| 五月婷婷综合激情| 国产美女一区二区三区| 99精品视频在线观看免费| 日本电影亚洲天堂一区| 日韩三级中文字幕| 国产精品美女www爽爽爽| 亚洲网友自拍偷拍| 国产一区二区三区最好精华液| 成人午夜av影视| 欧美日韩精品欧美日韩精品一| 久久一夜天堂av一区二区三区| 国产精品对白交换视频| 日韩激情一二三区| 国精产品一区一区三区mba视频 | 一区二区三区在线观看国产| 热久久国产精品| www.欧美.com| 精品日韩一区二区| 亚洲男人天堂av网| 国产九色精品成人porny| 欧美性色aⅴ视频一区日韩精品| 久久久久久免费网| 天堂va蜜桃一区二区三区| 成人午夜在线免费| 日韩美女一区二区三区四区| 亚洲精品欧美激情| 国产成人免费视频一区| 欧美一区二区网站| 一区二区三区欧美亚洲| 国产成人精品1024| 日韩欧美一区电影| 亚洲小说春色综合另类电影| 福利视频网站一区二区三区| 在线不卡免费av| 亚洲成a人v欧美综合天堂 | 国产精品一区二区三区99| 欧美无乱码久久久免费午夜一区| 国产亲近乱来精品视频| 另类人妖一区二区av| 欧美精品日日鲁夜夜添| 一区二区欧美在线观看| 9久草视频在线视频精品| 久久精品日韩一区二区三区| 蜜臀久久99精品久久久久久9 | 欧美成人免费网站| 婷婷亚洲久悠悠色悠在线播放| 91网站在线播放| 国产精品电影一区二区| 风间由美一区二区三区在线观看 | 国产精品99久久久久久久vr | 7777精品伊人久久久大香线蕉完整版 | 国产成人日日夜夜| 精品国内片67194| 日本在线不卡视频| 欧美区一区二区三区| 亚洲福利电影网| 欧美无人高清视频在线观看| 亚洲综合色婷婷| 欧美日韩三级在线| 亚洲电影第三页| 欧美一区二区三区在线看| 丝袜美腿亚洲一区|