Here, take all of these shits
This commit is contained in:
commit
e95ecbf23f
BIN
.README.md.swp
Normal file
BIN
.README.md.swp
Normal file
Binary file not shown.
BIN
.kqueue_file_watch.c.swp
Normal file
BIN
.kqueue_file_watch.c.swp
Normal file
Binary file not shown.
15
README.md
Normal file
15
README.md
Normal file
@ -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
|
BIN
bin/kque_file_watch
Executable file
BIN
bin/kque_file_watch
Executable file
Binary file not shown.
6
bin/test.txt
Normal file
6
bin/test.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
aaaaa
|
||||||
|
aaaaa
|
||||||
|
aaaaa
|
||||||
|
aaaaa
|
||||||
|
aaaaa
|
||||||
|
aaaaa
|
126
kqueue_file_watch.cpp
Normal file
126
kqueue_file_watch.cpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#include <sys/event.h>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
// #include <vector>
|
||||||
|
// #include <map>
|
||||||
|
#include <sys/param.h>
|
||||||
|
// #include <sys/epoll.h>
|
||||||
|
#include <sys/event.h>
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
typedef struct task_list_s {
|
||||||
|
siginfo_t admin;
|
||||||
|
pthread_t thread;
|
||||||
|
pthread_mutex_t queue_cond_lock;
|
||||||
|
// std::vector<MessageDef *> message_queue;
|
||||||
|
// std::map<long,timer_elm_t> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user