我想设置连接的最大值.如果它超过最大值,请告诉客户端现在服务器已满并关闭套接字.
如何用C编写代码?
谢谢.
解决方法
简单.在你调用accept()时,这样的事情:
new_conn = accept(listen_sock,&addr,addr_len); if (new_conn > 0) { if (total_connections < max_connections) { total_connections++; register_connection(new_conn); } else { send_reject_msg(new_conn); close(new_conn); } }
(当然,在丢失连接时减少total_connections).