commit e95ecbf23f28eb104c496258512f1677bfae1bf1 Author: User Infidel Date: Thu Sep 22 23:41:38 2022 +0700 Here, take all of these shits diff --git a/.README.md.swp b/.README.md.swp new file mode 100644 index 0000000..fd4c9ed Binary files /dev/null and b/.README.md.swp differ diff --git a/.kqueue_file_watch.c.swp b/.kqueue_file_watch.c.swp new file mode 100644 index 0000000..8bda661 Binary files /dev/null and b/.kqueue_file_watch.c.swp differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7e0347 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# What the fuck is this + +This is your lame attempt to understand how those Network Virtual Functions sofware works as well to sharpen your understanding on C++ and C programming language. + + +## Hints +- Compile using `g++` + +## Goal +- Understand the difference between c++ and C +- Understand how strcuct works and the difference between it on c++ and C +- Understand + +## Issues +- Modification to target file only detected after 2 or more interrupt diff --git a/bin/kque_file_watch b/bin/kque_file_watch new file mode 100755 index 0000000..36c7bc6 Binary files /dev/null and b/bin/kque_file_watch differ diff --git a/bin/test.txt b/bin/test.txt new file mode 100644 index 0000000..7050359 --- /dev/null +++ b/bin/test.txt @@ -0,0 +1,6 @@ +aaaaa +aaaaa +aaaaa +aaaaa +aaaaa +aaaaa diff --git a/kqueue_file_watch.cpp b/kqueue_file_watch.cpp new file mode 100644 index 0000000..defb023 --- /dev/null +++ b/kqueue_file_watch.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +// #include +// #include +#include +// #include +#include +// +// + + typedef struct task_list_s { + siginfo_t admin; + pthread_t thread; + pthread_mutex_t queue_cond_lock; + // std::vector message_queue; + // std::map timer_map; + uint64_t next_timer=UINT_MAX; + + /** Replace these shits **/ + struct epoll_event *events =NULL; + int nb_fd_epoll=0; + int epoll_fd=-1; + + /** kqueque equivalent **/ + + + int nb_events=0; + int sem_fd=-1; + } task_list_t; + +int main(int argc, char **argv){ + + struct kevent event1; + struct kevent event2; + struct kevent tevent; + struct kevent tevent2; + + struct epoll_event *events =NULL; + + + static task_list_t **tasks=NULL; + // printf("%s\n", task_list_t); + + // General Pointers + int kq, fd, ret1, ret2; + + // File Pointers + int fd1, fd2; + + kq = kqueue(); + + printf("%d number of args\n", argc); + + for (int i=1; i <= 2; i++){ + + printf("==> %s\n", argv[i]); + if (i == 1) + fd1 = open(argv[1], O_RDONLY); + if (i == 2) + fd2 = open(argv[2], O_RDONLY); + } + + // fd = open(argv[1], O_RDONLY); + + // for (int i=1; i <= 2; i++){ + // printf("YOUR FILES \n"); + // printf("==> %s\n", argv[i]); + // } + + + if (kq == -1){ + printf("Error kq...\n"); + return 0; + } + + /* initialzing kevent struct */ + EV_SET( + &event1, + fd1, + EVFILT_VNODE, + EV_ADD + | + EV_CLEAR, + NOTE_WRITE, + 0, + NULL + ); + + ret1 = kevent(kq, &event1, 1, NULL, 0, NULL); + + EV_SET( + &event2, + fd2, + EVFILT_VNODE, + EV_ADD + | + EV_CLEAR, + NOTE_WRITE, + 0, + NULL + ); + + ret2 = kevent(kq, &event2, 1, NULL, 0, NULL); + + if ( ret1 == -1 || ret2 == -1 ){ + printf("event failure to attched"); + } + + for (;;) { + ret1 = kevent(kq, NULL, 0, &tevent, 1, NULL); + ret2 = kevent(kq, NULL, 0, &tevent, 1, NULL); + if (ret1 == -1 || ret2 == -1) { + printf("Waiting.......\n"); + } else if ( ret1 > 0 || ret2 > 0 ){ + printf("Change detected on file...\n"); + printf("--> RET 1 VAL = %d\n", ret1); + printf("--> RET 2 VAL = %d\n", ret2); + } + // printf("--> RET 1 VAL = %d\n", ret1); + // printf("--> RET 2 VAL = %d\n", ret2); + } +} +