MCPcopy Create free account
hub / github.com/acl-dev/acl / read_callback

Method read_callback

lib_acl_cpp/samples/aio/aio_server/main.cpp:113–172  ·  view source on GitHub ↗

* ʵ�ָ����е��麯�����ͻ������Ķ��ɹ��ص����� * @param data {char*} ���������ݵ�ַ * @param len {int} ���������ݳ��� * @return {bool} ���� true ��ʾ����������ϣ���رո��첽�� */

Source from the content-addressed store, hash-verified

111 * @return {bool} ���� true ��ʾ����������ϣ���رո��첽��
112 */
113 bool read_callback(char* data, int len)
114 {
115 i_++;
116 if (i_ < 5) {
117 std::cout << ">>gets(i:" << i_ << "): "
118 << data << std::endl;
119 }
120
121 // ���Զ�̿ͻ���ϣ���˳�����ر�֮
122 if (strncasecmp(data, "quit", 4) == 0) {
123 client_->format("Bye!\r\n");
124 client_->close();
125 return false;
126 }
127
128 // ���Զ�̿ͻ���ϣ�������Ҳ�رգ�����ֹ�첽�¼�����
129 else if (strncasecmp(data, "stop", 4) == 0) {
130 client_->format("Stop now!\r\n");
131 client_->close(); // �ر�Զ���첽��
132
133 // ֪ͨ�첽����ر�ѭ������
134 client_->get_handle().stop();
135 }
136
137 // ��Զ�̿ͻ��˻�д�յ�������
138
139 int delay = 0;
140
141 if (!strncasecmp(data, "write_delay", strlen("write_delay"))) {
142 // �ӳ�д����
143
144 const char* ptr = data + strlen("write_delay");
145 delay = atoi(ptr);
146 if (delay > 0) {
147 std::cout << ">> write delay " << delay
148 << " second ..." << std::endl;
149 timer_writer* timer = new timer_writer(delay);
150 client_->write(data, len, delay * 1000000, timer);
151 client_->gets(10, false);
152 return true;
153 }
154 } else if (!strncasecmp(data, "read_delay", strlen("read_delay"))) {
155 // �ӳٶ�����
156
157 const char* ptr = data + strlen("read_delay");
158 delay = atoi(ptr);
159 if (delay > 0) {
160 client_->write(data, len);
161 std::cout << ">> read delay " << delay
162 << " second ..." << std::endl;
163 timer_reader* timer = new timer_reader(delay);
164 client_->gets(10, false, delay * 1000000, timer);
165 return true;
166 }
167 }
168
169 client_->write(data, len);
170 //client_->gets(10, false);

Callers

nothing calls this directly

Calls 7

strncasecmpFunction · 0.85
getsMethod · 0.80
formatMethod · 0.45
closeMethod · 0.45
stopMethod · 0.45
get_handleMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected