int main(int argc, char *argv[]) { errno = 0; assert(argc == 2); hook_init(); double num = strtod(argv[1], NULL); fprintf(stderr,"%x\n", sqrt); orig = (double (*)())hook_attach((uintptr_t)_sqrt, (hook_t)my_sqrt, 0); printf("%p,errno=%i\n", orig, hook_error(NULL, 0)); perror(""); if (orig == NULL) assert(orig != NULL); printf("\n\n%f => %f\n", num, _sqrt(num)); printf("%d", hook_detach((uintptr_t)_sqrt, (hook_t)orig)); }
bool aio_listen_stream::open(const char* addr) { ACL_VSTREAM *sstream = acl_vstream_listen(addr, 128); if (sstream == NULL) return false; snprintf(addr_, sizeof(addr_), "%s", ACL_VSTREAM_LOCAL(sstream)); stream_ = acl_aio_open(handle_->get_handle(), sstream); // 调用基类的 hook_error 以向 handle 中增加异步流计数, // 同时 hook 关闭及超时回调过程 hook_error(); // hook 监听的回调过程 hook_accept(); return true; }
aio_fstream::aio_fstream(aio_handle* handle, ACL_FILE_HANDLE fd, unsigned int oflags /* = 600 */) : aio_stream(handle), aio_istream(handle), aio_ostream(handle) { acl_assert(handle); acl_assert(fd != ACL_FILE_INVALID); ACL_VSTREAM* vstream = acl_vstream_fhopen(fd, oflags); stream_ = acl_aio_open(handle->get_handle(), vstream); // 调用基类的 hook_error 以向 handle 中增加异步流计数, // 同时 hook 关闭及超时回调过程 hook_error(); // 只有当流连接成功后才可 hook IO 读写状态 // hook 读回调过程 hook_read(); // hook 写回调过程 hook_write(); }
bool aio_fstream::open(const char* path, unsigned int oflags, unsigned int mode) { ACL_VSTREAM* fp = acl_vstream_fopen(path, oflags, mode, 8192); if (fp == NULL) return false; stream_ = acl_aio_open(handle_->get_handle(), fp); // 调用基类的 hook_error 以向 handle 中增加异步流计数, // 同时 hook 关闭及超时回调过程 hook_error(); // 只有当流连接成功后才可 hook IO 读写状态 // hook 读回调过程 if ((oflags & (O_RDONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC))) hook_read(); // hook 写回调过程 if ((oflags & (O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC))) hook_write(); return true; }