From e95ecbf23f28eb104c496258512f1677bfae1bf1 Mon Sep 17 00:00:00 2001 From: User Infidel Date: Thu, 22 Sep 2022 23:41:38 +0700 Subject: [PATCH] Here, take all of these shits --- .README.md.swp | Bin 0 -> 12288 bytes .kqueue_file_watch.c.swp | Bin 0 -> 12288 bytes README.md | 15 +++++ bin/kque_file_watch | Bin 0 -> 16720 bytes bin/test.txt | 6 ++ kqueue_file_watch.cpp | 126 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 .README.md.swp create mode 100644 .kqueue_file_watch.c.swp create mode 100644 README.md create mode 100755 bin/kque_file_watch create mode 100644 bin/test.txt create mode 100644 kqueue_file_watch.cpp diff --git a/.README.md.swp b/.README.md.swp new file mode 100644 index 0000000000000000000000000000000000000000..fd4c9edf2d00b11d39b7460abe61043ba4e3bef5 GIT binary patch literal 12288 zcmeI&F>ljA6bJAt6G#*g46LtY3{Fc}vY`?RbO-~YW$nd&wvX6%=I$L<7g!K0@Co>6 zj4j`ScTuXSNbS(A=vjWcSoYoh-*1cT`Oe|~3?`$o;^UrDzrR1uZ=c>$)lH?0Elq(< zx^w9<4@DNxe?mWMT&^#i@Oic1_Tpp2h*{^|2h3^v?cVN-+1{uvF5N|Lihu}QSs+rG zO*Ylj@spjj#^BKwJh*>w<>h3e2#A0Ph=2%)fCz|y2#CP-6QFKGec{+QR?+XS#*Kf* z)ujv~AOa#F0wN#+A|L`HAOa#F0wN#+*HA$7OZSsarJmj4@cjP&?En8M|2W~Aay{qT z<(hD9aRJvuu0K5I7uQd&A6(zK(mG$cBN)rqK6V6ZFo69KA_k>0IIso! zK-v~?{;GC81oC;z33}%j0n#&6BXEQgJ=z>$j?^PsFvQzKJ{&F|nx0?jf;sD_InXPo z8%TMkuI*AcF&JCHQ8gSMEfc@y1~{;KSDOHQ9=qtF(Jg`|!j}7Dj<{|n#i!Z@gg2a# z^TVO>6nU4I(dNl7KyYQR*=E&VfF7GBtrKePJ8o;a$$HV0h})c=wF&%9edTrArW=j6 ZRn!%ZxQzk4uQexPtTN_{l$SWS`U`{g#0dZZ literal 0 HcmV?d00001 diff --git a/.kqueue_file_watch.c.swp b/.kqueue_file_watch.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..8bda6610e3ff0cba4c8f3d33377934032112b350 GIT binary patch literal 12288 zcmeI2Piz!b9LFCJ6;%F2Vmz4O4+ywjcDvoxAfeqg4PCHFX|Zg}AH~UZ=1n_vc4j;C zwt^H))C6Oc=vfaY{yAt!j0Z8%gC=;;lb%czh!>4|K|Ppw^ZVY+c6YWE(qof1;j^>z z-uwN2@ArMb_ZGrT^-T^RrhUC7hHDFBZ(Pb*zx}#_O|NIn^&Qvdp6t2pH5J+Uh==n$ z?DYc6T-M-1;;=9~*W^u}Z-l{VZi(d4a9ocY&zr)U>9uYfPj_ksv;r$spedaEzK!g$ zQn623?%c7RwmvYiLMM8-RzNGD70?Q31+)TM0j+>mKr67C6%dUz>_sH7Hc8?_a$nPR zPagG6E1(t73TOqi0$KsBfL1^&pcT*xXa%$aT7gxlfN3*ktYa*?3zNtH|F{1A|Ho#= zegs#+C*U1$5j4SbUb4XnZ%)>GCBtQrN*V_!4E6@SWag#tA~ z*B4G^M?PPn@oJ4qG&wjzW!hyw>+i@>$VI8ApUJ`Ux`jb;i9xZ$pdBlAKr0NmoYn24 zc3T~oG5u*yHWzs7i`x|VB;Wb!?d?U9owFtGMVwrRGBWcbRj7{^7L*F=d(S!6@-6Qz z@s63UaQ$iclULfObf$cj%akuJdQ(q5)b=NphVHX`p8Fy*JC~!;iII^U_2p={P>ne% z#*G~_jyF1V|cN z0uZi3mRukE!t`Fi-bhN6A`vz%L6j}TDz(cG1=9?D>T91it%9tEA&Pc(F15F070%94 zypK?GY5{OQ#SZaBUM&yha)ow9>O?cc>G@~eQ%Q|=jXNQQR%VvJFn1_vd% zPZ)_W6SzlHezhuVPEX9zoRfrn%^<)mYZER`OW$i4=Hd6=`TucB|0m2a=EaK z@)g`nOA;w663Iz5;+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HVRu<^3=ej@$M{xi!hjbjtUFMSpXeQ95|?gbV^-yhgZ=J**C=` z`pqJt{dVVoGs0o?4}baWwu_z@`sYRd)Sa_%$@t~GTo3(>F5+g6EVryRWjM@0*~SU< OwUw5>o)KK8{(l20MFGnI literal 0 HcmV?d00001 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); + } +} +