2007年09月21日 星期五 17:28
junyi sun£¬ÄúºÃ£¡ ¡¡¡¡ÎÒ¶Ô DÓïÑÔ²»ÊǺÜÁ˽⣬µ«ÉÔÓÐһЩ½Ó´¥£¬¸Ð¾õËüµÄÓïÑÔ±¾ÉíÌ«¹ý¸´ÔÓÁË¡£¡£ ¿ÉÒÔ˵Ëü×î´óµÄ¸ÄÉÆºÍÁÁµã¾ÍÔÚÓÚ¶ÔÄÚ´æÊ¹Ó÷½Ãæ¡£ µ«ÊÇËüµÄһЩÓïÑÔÌØÐԿɲ»±ÈC++¼òµ¥¡£ C++µÄÄ£¿é¶¼ÒѾ¹»¸´ÔÓÁË¡£¡£ ×Ô´ÓÓÃÉÏpythonÒÔÀ´ÎÒʼÖÕ¾õµÃ simple is better ======== 2007-09-21 16:52:40 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ======== ½ñÌì¿´¼ûCSDNÉÏÃÍÍÆDÓïÑÔ£¬¾ÍÈ¥ÏÂÔØÁ˸ö±àÒëÆ÷ÍæÍæ¶ù¡£ ·¢ÏÖÓÖ¼¸¸öÌØµã±È½ÏÎüÒýÎÒ£º 1.²»ÐèÒªÐéÄâ»ú£¬³ÌÐòÌå»ýС 2.ÏñpythonµÄlistÒ»ÑùÓÅÑŵÄarray 3.ÕýÔò±í´ïʽ 4.GC 5.UnicodeÖ§³Ö 6.¿âËäÈ»²»¼°python,javaµÈÅӴ󣬵«std¿âÖÐÒ²´øÁËmd5/thread/socket/regex/zlibµÈ±È½ÏʵÓõĶ«¶« 7.¿çƽ̨ ....... ´ÓÔËÐеÄÐÔÄÜÉÏÀ´Ëµ£¬½ö´ÎÓÚ´¿C¡£ ÏÂÃæÊÇ×ªÔØÒ»¸öBenchmark: http://dlang.group.javaeye.com/group/topic/524 ÎÒ¸Õ¿ªÊ¼¿´£¬¶ÔDµÄÀí½âÒ²ºÜÓÐÏÞ£¬ÏÈÅ׿éש£¬ÏëÌýÌý¸ßÊÖÃǵĿ´·¨¡£ = = = = = = = = = = = = = = = = = = = = = = ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ö Àñ£¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÕÔÍþ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡zhaowei在pythonid.com ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2007-09-21 -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070921/01f0eeaa/attachment.htm
2007年09月21日 星期五 17:41
ȷʵ£¬DÓïÑÔÈç¹ûÑо¿ÉîÈëµÄ»°ÊDZȽϸ´ÔÓ£¬µ«ÊÇÈç¹ûÎÒÃÇÖ»ÓÃËü¿ª·¢Ó¦ÓóÌÐòµÄ»°£¬Æäʵ²»±ØÓõ½ºÜ¶à¸´ÔӵĻúÖÆ¡£
ÌùÒ»¸öSocket ServerµÄ³ÌÐò£º
/*
D listener written by Christopher E. Miller
This code is public domain.
You may use it for any purpose.
This code has no warranties and is provided 'as-is'.
*/
import std.conv;
import std.socket;
int main(char[][] args)
{
ushort port;
if(args.length >= 2)
{
port = std.conv.toUshort(args[1]);
}
else
{
port = 4444;
}
Socket listener = new TcpSocket;
assert(listener.isAlive);
listener.blocking = false;
listener.bind(new InternetAddress(port));
listener.listen(10);
printf("Listening on port %d.\n", cast(int)port);
const int MAX_CONNECTIONS = 60;
SocketSet sset = new SocketSet(MAX_CONNECTIONS + 1); // Room for
listener.
Socket[] reads;
for(;; sset.reset())
{
sset.add(listener);
foreach(Socket each; reads)
{
sset.add(each);
}
Socket.select(sset, null, null);
int i;
for(i = 0;; i++)
{
next:
if(i == reads.length)
break;
if(sset.isSet(reads[i]))
{
char[1024] buf;
int read = reads[i].receive(buf);
if(Socket.ERROR == read)
{
printf("Connection error.\n");
goto sock_down;
}
else if(0 == read)
{
try
{
//if the connection closed due to an error,
remoteAddress() could fail
printf("Connection from %.*s closed.\n",
reads[i].remoteAddress().toString());
}
catch
{
}
sock_down:
reads[i].close(); //release socket resources now
//remove from -reads-
if(i != reads.length - 1)
reads[i] = reads[reads.length - 1];
reads = reads[0 .. reads.length - 1];
printf("\tTotal connections: %d\n", reads.length);
goto next; //-i- is still the next index
}
else
{
printf("Received %d bytes from %.*s: \"%.*s\"\n", read,
reads[i].remoteAddress().toString(), buf[0 .. read]);
}
}
}
if(sset.isSet(listener)) //connection request
{
Socket sn;
try
{
if(reads.length < MAX_CONNECTIONS)
{
sn = listener.accept();
printf("Connection from %.*s established.\n",
sn.remoteAddress().toString());
assert(sn.isAlive);
assert(listener.isAlive);
reads ~= sn;
printf("\tTotal connections: %d\n", reads.length);
}
else
{
sn = listener.accept();
printf("Rejected connection from %.*s; too many
connections.\n", sn.remoteAddress().toString());
assert(sn.isAlive);
sn.close();
assert(!sn.isAlive);
assert(listener.isAlive);
}
}
catch(Exception e)
{
printf("Error accepting: %.*s\n", e.toString());
if(sn)
sn.close();
}
}
}
return 0;
}
On 9/21/07, ÕÔÍþ <zhaowei在pythonid.com> wrote:
>
> junyi sun£¬ÄúºÃ£¡
> ÎÒ¶Ô DÓïÑÔ²»ÊǺÜÁ˽⣬µ«ÉÔÓÐһЩ½Ó´¥£¬¸Ð¾õËüµÄÓïÑÔ±¾ÉíÌ«¹ý¸´ÔÓÁË¡£¡£
> ¿ÉÒÔ˵Ëü×î´óµÄ¸ÄÉÆºÍÁÁµã¾ÍÔÚÓÚ¶ÔÄÚ´æÊ¹Ó÷½Ãæ¡£
> µ«ÊÇËüµÄһЩÓïÑÔÌØÐԿɲ»±ÈC++¼òµ¥¡£
> C++µÄÄ£¿é¶¼ÒѾ¹»¸´ÔÓÁË¡£¡£
>
> ×Ô´ÓÓÃÉÏpythonÒÔÀ´ÎÒʼÖÕ¾õµÃ simple is better
>
>
> ======== 2007-09-21 16:52:40 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ========
>
>
> ½ñÌì¿´¼ûCSDNÉÏÃÍÍÆDÓïÑÔ£¬¾ÍÈ¥ÏÂÔØÁ˸ö±àÒëÆ÷ÍæÍæ¶ù¡£
> ·¢ÏÖÓÖ¼¸¸öÌØµã±È½ÏÎüÒýÎÒ£º
>
> 1.²»ÐèÒªÐéÄâ»ú£¬³ÌÐòÌå»ýС
> 2.ÏñpythonµÄlistÒ»ÑùÓÅÑŵÄarray
> 3.ÕýÔò±í´ïʽ
> 4.GC
> 5.UnicodeÖ§³Ö
> 6.¿âËäÈ»²»¼°python,javaµÈÅӴ󣬵«std¿âÖÐÒ²´øÁËmd5/thread/socket/regex/zlibµÈ±È½ÏʵÓõĶ«¶«
> 7.¿çƽ̨
>
> .......
>
> ´ÓÔËÐеÄÐÔÄÜÉÏÀ´Ëµ£¬½ö´ÎÓÚ´¿C¡£
> ÏÂÃæÊÇ×ªÔØÒ»¸öBenchmark:
> http://dlang.group.javaeye.com/group/topic/524
>
> ÎÒ¸Õ¿ªÊ¼¿´£¬¶ÔDµÄÀí½âÒ²ºÜÓÐÏÞ£¬ÏÈÅ׿éש£¬ÏëÌýÌý¸ßÊÖÃǵĿ´·¨¡£
>
>
> = = = = = = = = = = = = = = = = = = = = = =
>
> ÖÂ
> Àñ£¡
>
> ÕÔÍþ
> zhaowei在pythonid.com
> 2007-09-21
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070921/9d3c9e31/attachment.htm
2007年09月21日 星期五 17:47
建议去专门讨论D语言的地方去讨论,在这里你想得到什么样的结论? -- I like python! UliPad <>: http://code.google.com/p/ulipad/ My Blog: http://www.donews.net/limodou
Zeuux © 2025
京ICP备05028076号