acl/lib_acl/samples/server1/main.cpp
zsxxsz cf2528eb7c 完善了非阻塞IO的SSL功能;将 samples 移到 lib_acl 目录下
完善了非阻塞IO的SSL功能;将 acl/samples/ 下的示例分别移到 lib_acl 及 lib_protocol 目录下
2014-11-30 21:15:35 +08:00

52 lines
1.1 KiB
C++

#include "lib_acl.h"
#pragma comment(lib,"ws2_32")
#pragma comment(lib, "wsock32")
static void echo(ACL_VSTREAM *client)
{
int ret;
char buf[1024];
while (1) {
ret = acl_vstream_gets(client, buf, sizeof(buf));
if (ret == ACL_VSTREAM_EOF) {
break;
}
//ret = acl_vstream_fprintf(client, "hello world\r\nhello world\r\nhello world\r\n");
ret = acl_vstream_fprintf(client, "hello world\r\n");
if (ret == ACL_VSTREAM_EOF)
break;
}
}
int main(int argc, char *argv[])
{
ACL_VSTREAM *sstream, *client;
const char *addr = "127.0.0.1:30082";
acl_init();
sstream = acl_vstream_listen(addr, 128);
if (sstream == NULL) {
printf("listen on %s error(%s)\r\n", addr, acl_last_serror());
getchar();
return (0);
}
printf("listening on %s ...\r\n", addr);
while (1) {
client = acl_vstream_accept(sstream, NULL, 0);
if (client == NULL) {
printf("accept error(%s)\r\n", acl_last_serror());
break;
}
echo(client);
acl_vstream_close(client);
}
printf("Over now\r\n");
getchar();
return (0);
}