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

Method setup_hook

lib_acl_cpp/src/stream/aio_stream.cpp:523–573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

521#define HOOK_KEY "aio_stream::setup_hook"
522
523stream_hook* aio_stream::setup_hook(stream_hook* hook)
524{
525 ACL_VSTREAM* vstream = get_vstream();
526 if (vstream == NULL) {
527 logger_error("vstream null");
528 return NULL;
529 }
530
531 stream_hook* old_hook = hook_;
532
533 if (vstream->type == ACL_VSTREAM_TYPE_FILE) {
534 ACL_FSTREAM_RD_FN read_fn = vstream->fread_fn;
535 ACL_FSTREAM_WR_FN write_fn = vstream->fwrite_fn;
536
537 vstream->fread_fn = fread_hook;
538 vstream->fwrite_fn = fsend_hook;
539 acl_vstream_add_object(vstream, HOOK_KEY, this);
540
541 if (hook->open(vstream) == false) {
542 // �����ʧ�ܣ���ָ�
543
544 vstream->fread_fn = read_fn;
545 vstream->fwrite_fn = write_fn;
546 acl_vstream_del_object(vstream, HOOK_KEY);
547 return hook;
548 }
549 } else {
550 ACL_VSTREAM_RD_FN read_fn = vstream->read_fn;
551 ACL_VSTREAM_WR_FN write_fn = vstream->write_fn;
552
553 vstream->read_fn = read_hook;
554 vstream->write_fn = send_hook;
555 acl_vstream_add_object(vstream, HOOK_KEY, this);
556
557 if (acl_getsocktype(ACL_VSTREAM_SOCK(vstream)) == SOCK_STREAM) {
558 acl_tcp_set_nodelay(ACL_VSTREAM_SOCK(vstream));
559 }
560
561 if (hook->open(vstream) == false) {
562 // �����ʧ�ܣ���ָ�
563
564 vstream->read_fn = read_fn;
565 vstream->write_fn = write_fn;
566 acl_vstream_del_object(vstream, HOOK_KEY);
567 return hook;
568 }
569 }
570
571 hook_ = hook;
572 return old_hook;
573}
574
575int aio_stream::read_hook(ACL_SOCKET, void *buf, size_t len,
576 int, ACL_VSTREAM* vs, void *)

Callers

nothing calls this directly

Calls 5

acl_vstream_add_objectFunction · 0.85
acl_vstream_del_objectFunction · 0.85
acl_getsocktypeFunction · 0.85
acl_tcp_set_nodelayFunction · 0.85
openMethod · 0.45

Tested by

no test coverage detected