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

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

?? winhandl.c

?? putty
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * winhandl.c: Module to give Windows front ends the general
 * ability to deal with consoles, pipes, serial ports, or any other
 * type of data stream accessed through a Windows API HANDLE rather
 * than a WinSock SOCKET.
 *
 * We do this by spawning a subthread to continuously try to read
 * from the handle. Every time a read successfully returns some
 * data, the subthread sets an event object which is picked up by
 * the main thread, and the main thread then sets an event in
 * return to instruct the subthread to resume reading.
 * 
 * Output works precisely the other way round, in a second
 * subthread. The output subthread should not be attempting to
 * write all the time, because it hasn't always got data _to_
 * write; so the output thread waits for an event object notifying
 * it to _attempt_ a write, and then it sets an event in return
 * when one completes.
 * 
 * (It's terribly annoying having to spawn a subthread for each
 * direction of each handle. Technically it isn't necessary for
 * serial ports, since we could use overlapped I/O within the main
 * thread and wait directly on the event objects in the OVERLAPPED
 * structures. However, we can't use this trick for some types of
 * file handle at all - for some reason Windows restricts use of
 * OVERLAPPED to files which were opened with the overlapped flag -
 * and so we must use threads for those. This being the case, it's
 * simplest just to use threads for everything rather than trying
 * to keep track of multiple completely separate mechanisms.)
 */

#include <assert.h>

#include "putty.h"

/* ----------------------------------------------------------------------
 * Generic definitions.
 */

/*
 * Maximum amount of backlog we will allow to build up on an input
 * handle before we stop reading from it.
 */
#define MAX_BACKLOG 32768

struct handle_generic {
    /*
     * Initial fields common to both handle_input and handle_output
     * structures.
     * 
     * The three HANDLEs are set up at initialisation time and are
     * thereafter read-only to both main thread and subthread.
     * `moribund' is only used by the main thread; `done' is
     * written by the main thread before signalling to the
     * subthread. `defunct' and `busy' are used only by the main
     * thread.
     */
    HANDLE h;			       /* the handle itself */
    HANDLE ev_to_main;		       /* event used to signal main thread */
    HANDLE ev_from_main;	       /* event used to signal back to us */
    int moribund;		       /* are we going to kill this soon? */
    int done;			       /* request subthread to terminate */
    int defunct;		       /* has the subthread already gone? */
    int busy;			       /* operation currently in progress? */
    void *privdata;		       /* for client to remember who they are */
};

/* ----------------------------------------------------------------------
 * Input threads.
 */

/*
 * Data required by an input thread.
 */
struct handle_input {
    /*
     * Copy of the handle_generic structure.
     */
    HANDLE h;			       /* the handle itself */
    HANDLE ev_to_main;		       /* event used to signal main thread */
    HANDLE ev_from_main;	       /* event used to signal back to us */
    int moribund;		       /* are we going to kill this soon? */
    int done;			       /* request subthread to terminate */
    int defunct;		       /* has the subthread already gone? */
    int busy;			       /* operation currently in progress? */
    void *privdata;		       /* for client to remember who they are */

    /*
     * Data set at initialisation and then read-only.
     */
    int flags;

    /*
     * Data set by the input thread before signalling ev_to_main,
     * and read by the main thread after receiving that signal.
     */
    char buffer[4096];		       /* the data read from the handle */
    DWORD len;			       /* how much data that was */
    int readerr;		       /* lets us know about read errors */

    /*
     * Callback function called by this module when data arrives on
     * an input handle.
     */
    handle_inputfn_t gotdata;
};

/*
 * The actual thread procedure for an input thread.
 */
static DWORD WINAPI handle_input_threadfunc(void *param)
{
    struct handle_input *ctx = (struct handle_input *) param;
    OVERLAPPED ovl, *povl;
    HANDLE oev;
    int readret, readlen;

    if (ctx->flags & HANDLE_FLAG_OVERLAPPED) {
	povl = &ovl;
	oev = CreateEvent(NULL, TRUE, FALSE, NULL);
    } else {
	povl = NULL;
    }

    if (ctx->flags & HANDLE_FLAG_UNITBUFFER)
	readlen = 1;
    else
	readlen = sizeof(ctx->buffer);

    while (1) {
	if (povl) {
	    memset(povl, 0, sizeof(OVERLAPPED));
	    povl->hEvent = oev;
	}
	readret = ReadFile(ctx->h, ctx->buffer,readlen, &ctx->len, povl);
	if (!readret)
	    ctx->readerr = GetLastError();
	else
	    ctx->readerr = 0;
	if (povl && !readret && ctx->readerr == ERROR_IO_PENDING) {
	    WaitForSingleObject(povl->hEvent, INFINITE);
	    readret = GetOverlappedResult(ctx->h, povl, &ctx->len, FALSE);
	    if (!readret)
		ctx->readerr = GetLastError();
	    else
		ctx->readerr = 0;
	}

	if (!readret) {
	    /*
	     * Windows apparently sends ERROR_BROKEN_PIPE when a
	     * pipe we're reading from is closed normally from the
	     * writing end. This is ludicrous; if that situation
	     * isn't a natural EOF, _nothing_ is. So if we get that
	     * particular error, we pretend it's EOF.
	     */
	    if (ctx->readerr == ERROR_BROKEN_PIPE)
		ctx->readerr = 0;
	    ctx->len = 0;
	}

	if (readret && ctx->len == 0 &&
	    (ctx->flags & HANDLE_FLAG_IGNOREEOF))
	    continue;

	SetEvent(ctx->ev_to_main);

	if (!ctx->len)
	    break;

	WaitForSingleObject(ctx->ev_from_main, INFINITE);
	if (ctx->done)
	    break;		       /* main thread told us to shut down */
    }

    if (povl)
	CloseHandle(oev);

    return 0;
}

/*
 * This is called after a succcessful read, or from the
 * `unthrottle' function. It decides whether or not to begin a new
 * read operation.
 */
static void handle_throttle(struct handle_input *ctx, int backlog)
{
    if (ctx->defunct)
	return;

    /*
     * If there's a read operation already in progress, do nothing:
     * when that completes, we'll come back here and be in a
     * position to make a better decision.
     */
    if (ctx->busy)
	return;

    /*
     * Otherwise, we must decide whether to start a new read based
     * on the size of the backlog.
     */
    if (backlog < MAX_BACKLOG) {
	SetEvent(ctx->ev_from_main);
	ctx->busy = TRUE;
    }
}

/* ----------------------------------------------------------------------
 * Output threads.
 */

/*
 * Data required by an output thread.
 */
struct handle_output {
    /*
     * Copy of the handle_generic structure.
     */
    HANDLE h;			       /* the handle itself */
    HANDLE ev_to_main;		       /* event used to signal main thread */
    HANDLE ev_from_main;	       /* event used to signal back to us */
    int moribund;		       /* are we going to kill this soon? */
    int done;			       /* request subthread to terminate */
    int defunct;		       /* has the subthread already gone? */
    int busy;			       /* operation currently in progress? */
    void *privdata;		       /* for client to remember who they are */

    /*
     * Data set at initialisation and then read-only.
     */
    int flags;

    /*
     * Data set by the main thread before signalling ev_from_main,
     * and read by the input thread after receiving that signal.
     */
    char *buffer;		       /* the data to write */
    DWORD len;			       /* how much data there is */

    /*
     * Data set by the input thread before signalling ev_to_main,
     * and read by the main thread after receiving that signal.
     */
    DWORD lenwritten;		       /* how much data we actually wrote */
    int writeerr;		       /* return value from WriteFile */

    /*
     * Data only ever read or written by the main thread.
     */
    bufchain queued_data;	       /* data still waiting to be written */

    /*
     * Callback function called when the backlog in the bufchain
     * drops.
     */
    handle_outputfn_t sentdata;
};

static DWORD WINAPI handle_output_threadfunc(void *param)
{
    struct handle_output *ctx = (struct handle_output *) param;
    OVERLAPPED ovl, *povl;
    int writeret;

    if (ctx->flags & HANDLE_FLAG_OVERLAPPED)
	povl = &ovl;
    else
	povl = NULL;

    while (1) {
	WaitForSingleObject(ctx->ev_from_main, INFINITE);
	if (ctx->done) {
	    SetEvent(ctx->ev_to_main);
	    break;
	}
	if (povl)
	    memset(povl, 0, sizeof(OVERLAPPED));
	writeret = WriteFile(ctx->h, ctx->buffer, ctx->len,
			     &ctx->lenwritten, povl);
	if (!writeret)
	    ctx->writeerr = GetLastError();
	else
	    ctx->writeerr = 0;
	if (povl && !writeret && GetLastError() == ERROR_IO_PENDING) {
	    writeret = GetOverlappedResult(ctx->h, povl,
					   &ctx->lenwritten, TRUE);
	    if (!writeret)
		ctx->writeerr = GetLastError();
	    else
		ctx->writeerr = 0;
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品入口麻豆原神| 欧美成人激情免费网| 成人精品亚洲人成在线| 亚洲国产sm捆绑调教视频| 欧美精品aⅴ在线视频| 亚洲欧美在线视频| 国产电影一区在线| 欧美色图激情小说| 久久精品国内一区二区三区| a级精品国产片在线观看| 中文字幕亚洲在| 欧美一级免费观看| 韩国精品在线观看| 色婷婷久久一区二区三区麻豆| 精品国产伦一区二区三区观看体验| 欧美精品国产精品| 91国偷自产一区二区开放时间 | 欧美精品tushy高清| 在线视频你懂得一区二区三区| 91网址在线看| 91网上在线视频| 91女神在线视频| 在线观看亚洲一区| 亚洲成人综合视频| 国产一区二区三区| 日韩美女视频一区| 欧美日韩国产精选| 久久久www成人免费无遮挡大片| 制服丝袜亚洲精品中文字幕| 日韩天堂在线观看| 一区二区三区在线影院| 这里只有精品免费| 国产亚洲欧美在线| 亚洲制服欧美中文字幕中文字幕| 麻豆精品视频在线观看免费| 日韩一区欧美一区| 久久久综合激的五月天| 久久久久久一级片| 日本一区二区三区国色天香| 亚洲一区二区不卡免费| 亚洲同性同志一二三专区| 91精品久久久久久久99蜜桃 | 国产一区二区女| 亚洲一区av在线| 欧美性极品少妇| 菠萝蜜视频在线观看一区| 成人av手机在线观看| 色婷婷久久一区二区三区麻豆| 色狠狠色噜噜噜综合网| 日韩一区二区三区四区五区六区 | 欧美天堂亚洲电影院在线播放| 欧美日韩在线播放一区| 一区二区视频在线看| 欧美韩日一区二区三区四区| 亚洲精品久久7777| 九九视频精品免费| 一本到三区不卡视频| 欧美一区二区三区日韩视频| 亚洲国产成人在线| 精品一区二区三区视频| 日本怡春院一区二区| 久久综合九色综合97_久久久| 91啪亚洲精品| av在线综合网| 日韩一区二区视频| 日韩午夜在线观看| 国产性天天综合网| 青青草国产成人av片免费| 美女一区二区在线观看| 一区二区三区四区亚洲| 亚洲欧美在线视频| 国内精品免费**视频| 激情偷乱视频一区二区三区| 在线国产亚洲欧美| 国产亚洲一本大道中文在线| 久久久久久9999| 国产成人综合亚洲91猫咪| 欧美日韩一区二区三区不卡| 国产精品污网站| 国产黄色成人av| 精品播放一区二区| 美女性感视频久久| 欧美日韩mp4| 亚洲午夜激情av| 欧美日韩免费一区二区三区视频| 国产女同性恋一区二区| 国产黑丝在线一区二区三区| 日韩一级黄色片| 亚洲精品菠萝久久久久久久| 国产一区二区成人久久免费影院| 欧美片在线播放| 午夜视频在线观看一区二区 | 精品视频1区2区| 亚洲一级片在线观看| 欧美私人免费视频| 日本中文字幕一区二区视频| 欧美喷水一区二区| 蜜臀久久久99精品久久久久久| 精品1区2区3区| 蜜臀久久99精品久久久久久9| 欧美日韩一区久久| 国产精品久久久久一区二区三区| 成人激情免费视频| 国内成人精品2018免费看| 久久亚洲二区三区| 成人精品一区二区三区四区| 亚洲在线观看免费视频| 欧美大片国产精品| 91欧美一区二区| 蜜桃视频第一区免费观看| 中文字幕亚洲成人| 秋霞影院一区二区| 精品久久一二三区| 成人中文字幕在线| 亚洲成人动漫av| 国产午夜精品在线观看| 欧美视频一区二区三区在线观看| 国产精品一品视频| 调教+趴+乳夹+国产+精品| 亚洲国产精品ⅴa在线观看| 777奇米四色成人影色区| 成人黄色小视频在线观看| 琪琪久久久久日韩精品| 亚洲免费观看高清在线观看| 91精品国产欧美一区二区| av亚洲精华国产精华| 久久 天天综合| 午夜电影网亚洲视频| 国产精品国产三级国产有无不卡| 欧美三级视频在线| 国产精品主播直播| 九九国产精品视频| 日韩影院免费视频| 亚洲国产日日夜夜| 亚洲永久精品大片| 国产日产欧产精品推荐色 | 亚洲综合激情网| 日韩午夜在线影院| 日韩亚洲电影在线| 日韩精品中文字幕在线一区| 欧美艳星brazzers| 欧美色综合久久| 欧美人狂配大交3d怪物一区| 欧美色图在线观看| 欧美精品亚洲二区| 欧美一区二区三级| 精品福利一区二区三区免费视频| 91精品国产免费久久综合| 91精品久久久久久久99蜜桃| 亚洲精品一区二区三区在线观看| 2022国产精品视频| 日韩精品一区二区三区三区免费| 欧美精品一区二区三区高清aⅴ| 精品欧美乱码久久久久久1区2区| 国产午夜亚洲精品不卡| 亚洲人成精品久久久久| 午夜精品久久久久| 国产老肥熟一区二区三区| 91久久精品国产91性色tv| 91精品麻豆日日躁夜夜躁| 欧美一区二区三区电影| 精品国偷自产国产一区| 国产精品卡一卡二| 久久99精品视频| 色香色香欲天天天影视综合网| 日韩一区二区三区在线观看| 中文字幕精品在线不卡| 免费看日韩a级影片| 99re这里只有精品首页| 久久免费国产精品| 亚洲国产成人tv| 大胆亚洲人体视频| 日韩欧美精品在线| 一区二区三区成人在线视频| 蜜桃在线一区二区三区| 欧美视频在线观看一区二区| 中文成人av在线| 久久66热偷产精品| 欧美成人午夜电影| 亚洲色图另类专区| 国产成人在线网站| 国产日产欧产精品推荐色| 免费成人性网站| 欧美老年两性高潮| 亚洲午夜成aⅴ人片| 在线观看精品一区| 一区二区三区日韩在线观看| 视频一区二区中文字幕| 91伊人久久大香线蕉| 国产欧美一区二区三区鸳鸯浴| 国产在线播放一区二区三区| 日韩你懂的在线观看| 久久99精品久久久| 日韩你懂的在线观看| 日韩高清不卡一区二区三区| 日韩一级二级三级| 九色综合国产一区二区三区| 精品国产乱码久久久久久1区2区| 极品瑜伽女神91| 中文字幕一区二区三区色视频|