网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  微软代码     
  文章作者:未知  文章来源:水木森林  
  查看:110次  录入:管理员--2007-11-17  
 
  ntel corporation proprietary information
copyright (c) 1995 intel corporation

this listing is supplied under the terms of a license agreement with
intel corporation and may not be used, copied, nor disclosed except in
accordance with the terms of that agreeement.

module name:

select.c

abstract:

this module contains the “select“ entry points from the winsock
api. the following functions aare contained in this module.

select()
wsaeventselect()
wsaasyncselect()
__wsafdisset()

author:

dirk brandewie dirk@mink.intel.com 14-06-1995

revision history:

22-aug-1995 dirk@mink.intel.com
cleanup after code review. moved includes to precomp.h

16-aug-1995 dirk@mink.intel.com
added implementation of __wsafdisset

--*/
#include “precomp.h“

int wsaapi
select (
in int nfds,
in out fd_set far *readfds,
in out fd_set far *writefds,
in out fd_set far *exceptfds,
in const struct timeval far *timeout
)
/*++
routine description:

determine the status of one or more sockets, waiting if necessary.

arguments:

nfds - this argument is ignored and included only for the sake of
compatibility.

readfds - an optional pointer to a set of sockets to be checked
for readability.

writefds - an optional pointer to a set of sockets to be checked
for writability.

exceptfds - an optional pointer to a set of sockets to be checked
for errors.

timeout - the maximum time for select() to wait, or null for
blocking operation.

returns:
select() returns the total number of descriptors which are ready
and contained in the fd_set structures, 0 if the time limit
expired, or socket_error if an error occurred. if the return
value is socket_error, the error code is stored with
setlasterror().
--*/
{
int returnvalue;
int errorcode;
pdprovider provider;
pdsocket socket;
socket socketid;
bool foundsocket=false;

errorcode = turbo_prolog();

if (errorcode == error_success) {

__try {
// look for a socket in the three fd_sets handed in. the first
// socket found will be used to select the service provider to
// service this call
if (readfds && readfds->fd_count)
{
socketid = readfds->fd_array[0];
foundsocket = true;
} //if

if (!foundsocket && writefds && writefds->fd_count )
{
socketid = writefds->fd_array[0];
foundsocket = true;
} //if

if (!foundsocket && exceptfds && exceptfds->fd_count )
{
socketid = exceptfds->fd_array[0];
foundsocket = true;
} //if
}
__except (ws2_exception_filter()) {
errorcode = wsaefault;
goto returnerror;
}

if (foundsocket) {
socket = dsocket::getcounteddsocketfromsocket(socketid);
if(socket != null){
provider = socket->getdprovider();
returnvalue = provider->wspselect(
nfds,
readfds,
writefds,
exceptfds,
timeout,
&errorcode);
socket->dropdsocketreference();
if (returnvalue!=socket_error)
return returnvalue;

assert (errorcode!=no_error);
if (errorcode==no_error)
errorcode = wsasyscallfailure;

} //if
else {
errorcode = wsaenotsock;
}
} //if
else {
errorcode = wsaeinval;
} //else
}

returnerror:
setlasterror(errorcode);
return(socket_error);
} //select

int wsaapi
wsaeventselect(
in socket s,
in wsaevent heventobject,
in long lnetworkevents
)
/*++
routine description:

specify an event object to be associated with the supplied set of
fd_xxx network events.

arguments:

s - a descriptor identifying the socket.

heventobject - a handle identifying the event object to be
associated with the supplied set of fd_xxx network
events.

lnetworkevents - a bitmask which specifies the combination of
fd_xxx network events in which the application
has interest.

returns:
zero on success else socket_error. the error code is stored with
setlasterror().
--*/
{
int returnvalue;
int errorcode;
pdprovider provider;
pdsocket socket;

errorcode = turbo_prolog();

if (errorcode == error_success) {
socket = dsocket::getcounteddsocketfromsocket(s);
if(socket != null){
provider = socket->getdprovider();
returnvalue = provider->wspeventselect(
s,
heventobject,
lnetworkevents,
&errorcode);
socket->dropdsocketreference();
if (returnvalue==error_success)
return returnvalue;
assert (errorcode!=no_error);
if (errorcode==no_error)
errorcode = wsasyscallfailure;
}
else {
errorcode = wsaenotsock;
}
}

setlasterror(errorcode);
return socket_error;
} //wsaeventselect

int wsaapi
wsaasyncselect(
in socket s,
in hwnd hwnd,
in u_int wmsg,
in long levent
)
/*++
routine description:

request event notification for a socket.

arguments:

s - a descriptor identifying the socket for which event notification is
required.

hwnd - a handle identifying the window which should receive a message when
a network event occurs.

wmsg - the message to be received when a network event occurs.

levent - a bitmask which specifies a combination of network events in which
the application is interested.

returns:
the return value is 0 if the application‘s declaration of interest in the
network event set was successful. otherwise the value socket_error is
returned, and a specific error number may be retrieved by calling
wsagetlasterror().
--*/
{
int returnvalue;
int errorcode;
pdprovider provider;
pdsocket socket;

errorcode = turbo_prolog();

if (errorcode == error_success) {
socket = dsocket::getcounteddsocketfromsocket(s);
if(socket != null){
provider = socket->getdprovider();
returnvalue = provider->wspasyncselect(
s,
hwnd,
wmsg,
levent,
&errorcode);
socket->dropdsocketreference();
if (returnvalue==error_success)
return returnvalue;
assert (errorcode!=no_error);
if (errorcode==no_error)
errorcode = wsasyscallfailure;
}
else {
errorcode = wsaenotsock;
}
}

setlasterror(errorcode);
return socket_error;
} //wsaasyncselect

int far pascal
__wsafdisset(
socket fd,
fd_set far *set)
/*++
routine description:

determines if a specific socket is a contained in an fd_set.

arguments:

s - a descriptor identifying the socket.

set - a pointer to an fd_set.
returns:

returns true if socket s is a member of set, otherwise false.

--*/
{
int i = set->fd_count; // index into fd_set
int rc=false; // user return code

while (i--){
if (set->fd_array[i] == fd) {
rc = true;
} //if
} //while
return (rc);
} // __wsafdisset

int far pascal
wpufdisset(
socket fd,
fd_set far *set)
/*++
routine description:

determines if a specific socket is a contained in an fd_set.

arguments:

s - a descriptor identifying the socket.

set - a pointer to an fd_set.
returns:

returns true if socket s is a member of set, otherwise false.

--*/
{
int return_value;

return_value = __wsafdisset(
fd,
set
);
return(return_value);
} // wpufdisset
 
 
上一篇: 网上选课系统.java    下一篇: 为apache加速
  相关文档
microsoft jscript 特性 - 非-ecma 11-16
java入门及faq__1(4) 11-17
用actionform一次获取表单所有参数 11-17
优化jdbc性能的三大技巧 11-16
搭建java桌面应用程序原型(二) 11-17
java数据流——企业级数据流分析(组图) 11-17
用javahelp系统开发和交付更好的文档 11-16
入门基础:java用synth自定义皮肤 11-17
jar文件包间接及jar命令开发实例详解 11-17
java程序性能调优的基本知识和jdk调优 11-17
struts的动态表单的应用 11-17
在网页中控制wmplayer播放器 11-16
jca适配器技术综述 11-17
j2ee基础:hibernate中的参数使用详解 11-16
jml起步--使用jml 改进你的java程序(4) 11-17
movefile 方法 11-16
java入门笔记7_stream 11-17
[学习笔记]thinking in java (the 2nd edition) study note (3) 11-17
java版本和c++版本简单stack程序 11-17
java高级:多核线程-volatile原理与技巧 11-16
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息