-
Notifications
You must be signed in to change notification settings - Fork 4
for code review #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hurley25
wants to merge
88
commits into
code-review
Choose a base branch
from
master
base: code-review
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
f22ff46
base
ghorges 00267e0
first
ghorges 215e774
README.md
ghorges e4b0020
some bugs
ghorges 2caf692
some bugs
ghorges a649e42
README.md
ghorges 3dad36b
some bugs
ghorges 81ef090
version2
ghorges fb5117e
change bugs
ghorges 03723fc
修复了Epoll
yaomer 382311f
deleted old version
yaomer 32b80af
deleted old files
yaomer 4a2d923
new version
yaomer 154c361
x
yaomer b739268
Create LICENSE
okokme c4acc5a
线程使用std::thread
yaomer cb96a3e
Merge branch 'master' of https://github.com/xiyou-linuxer/deepin-file…
yaomer b05ea29
deleted tmp.c
yaomer bad9c28
deleted tmp.cc
yaomer 1c8b064
Merge branch 'master' of https://github.com/xiyou-linuxer/deepin-file…
yaomer ed68e7e
fix bug
ghorges 266bbdf
fix bug
ghorges 5739883
fix bug
ghorges 4f1a9b5
fix bug
ghorges 2a87c7e
fix bug
ghorges 4f5df04
README.md
ghorges d4f7b09
README.md
ghorges 7587041
README.md
ghorges 3e74dbe
add some sh
ghorges d4cab0e
rmversion1
ghorges 63f1d74
rmversion1
ghorges ee0d4a6
server
ghorges f3fbf88
rm log
ghorges bfcf227
update project.md
yaomer c408d28
Merge branch 'master' of https://github.com/xiyou-linuxer/deepin-file…
yaomer 21ca0c4
rm-client
ghorges cc80785
Merge branch 'master' of https://github.com/xiyou-linuxer/deepin-file…
ghorges 15220dd
fix-some-bugs
ghorges 0769744
fix-bugs
ghorges ef6e72d
change build.sh
ghorges ce0ad7d
fix-bugs
ghorges be77e60
rm log
ghorges e5f8325
update
ghorges 229ba52
Update myhook.c
ghorges b8f9ac3
Update threadpool.h
ghorges 95078df
fix-bugs
ghorges feb134a
update Buffer
yaomer ea6320a
Merge branch 'master' of https://github.com/xiyou-linuxer/deepin-file…
yaomer a07e24e
add zip
ghorges 2304cc9
add zip
ghorges c6ce3c4
add zip
ghorges 1aea1b1
Update README.md
ghorges 6432bf1
Update README.md
ghorges 277528a
add zip
ghorges 4b68cbc
Merge branch 'master' of https://github.com/xiyou-linuxer/deepin-file…
ghorges 8061764
move server src by:<xiyoulinuxgroup>
ghorges 4b0ea81
fix make.sh bugs by:<xiyoulinuxgroup>
ghorges ce4ccdd
fix some bugs by:<xiyoulinuxgroup>
ghorges bc6fbc0
fix some bugs by:<xiyoulinuxgroup>
ghorges b9f72a8
fix some bugs by:<xiyoulinuxgroup>
ghorges d8e5be4
fix some bugs by:<xiyoulinuxgroup>
ghorges 3cdf5a4
fix some bugs by:<xiyoulinuxgroup>
ghorges 54fac31
Update README.md
okokme 89b025c
Update README.md
okokme 09dab5e
Update README.md
okokme c0609a4
Update README.md
okokme 220dae9
Update README.md
okokme de75377
add doc by:<xiyoulinuxgroup>
okokme 3403e7f
Update README.md
okokme 8591628
Update README.md
okokme 433f15c
update build.sh
yaomer 8ca64af
fix some bugs by:<xiyoulinuxgroup>
ghorges d037f22
Update README.md
jialuhu bf412e9
fix some bugs by:<xiyoulinuxgroup>
ghorges 4ee24c9
fix some note
jialuhu 0c9961c
Update README.md
jialuhu 6800fa0
Update README.md
jialuhu edb67d7
Update README.md
jialuhu d8fa877
Update README.md
jialuhu 6f491ac
Update README.md
jialuhu f8ee1f5
Update README.md
jialuhu 0edaa3b
fix some bugs by:<xiyoulinuxgroup>
ghorges e34f9dc
add zip
ghorges ff65386
add zip
ghorges 973e9fb
picture
ff94b4e
Update README.md
ghorges 8539bff
Update README.md
ghorges 10b2315
Update README.md
jialuhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2019 xiyoulinuxgroup | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| join in deepin_os_match2019 |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #这个是连接的端口 | ||
| port:8888 | ||
| #这个是服务器的地址 | ||
| addr:132.232.63.90 | ||
| #这是监测的路径,路径请使用绝对路径 | ||
| path:/home/ma/deepin-file-control/etc | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| PATHS=`pwd` | ||
| REA+=$PATHS | ||
| REA+="/test/myhook.so" | ||
| `echo $REA > /etc/ld.so.preload` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/bash | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| PATHS=`pwd` | ||
| REA="#define FILE_PATH \"" | ||
| REA+=$PATHS | ||
| REA+="/etc/file.conf" | ||
| REA+="\"" | ||
| `echo $REA >> src/hook/myhook.h` | ||
| `echo $REA >> src/cli/fconf.h` | ||
|
|
||
| UNIXS="unix:" | ||
| UNIXS+=$PATHS | ||
| UNIXS+="/etc/unix" | ||
| `echo $UNIXS >> etc/file.conf` | ||
|
|
||
| g++ -std=c++11 -o ./src/cli/client ./src/cli/*.cpp -lpthread -ldl | ||
|
|
||
| cd src/hook | ||
| `chmod 777 build.sh` | ||
| `./build.sh` | ||
| cd ../.. | ||
|
|
||
| `touch etc/unix` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用 (
cd src/server
chmod 777 build.sh
./build.sh
)这样就不需要记得返回到上一层多少次了。 |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include <iostream> | ||
| #include <sys/uio.h> | ||
| #include "Buffer.h" | ||
|
|
||
| // 将fd中的数据读到Buffer中 | ||
| int Buffer::readFd(int fd) | ||
| { | ||
| char extrabuf[65536]; | ||
| struct iovec iov[2]; | ||
| ssize_t writen = writeable(); | ||
| ssize_t n; | ||
|
|
||
| iov[0].iov_base = begin() + _writeindex; | ||
| iov[0].iov_len = writen; | ||
| iov[1].iov_base = extrabuf; | ||
| iov[1].iov_len = sizeof(extrabuf); | ||
|
|
||
| if ((n = readv(fd, iov, 2)) > 0) { | ||
| if (n <= writen) | ||
| _writeindex += n; | ||
| else { | ||
| _writeindex += writen; | ||
| append(extrabuf, n - writen); | ||
| } | ||
| } | ||
| return n; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #ifndef _ANGEL_BUFFER_H | ||
| #define _ANGEL_BUFFER_H | ||
|
|
||
| #include <vector> | ||
| #include <algorithm> | ||
|
|
||
| class Buffer { | ||
| public: | ||
| Buffer() : _buf(INIT_SIZE) { } | ||
| ~Buffer() { } | ||
| static const size_t INIT_SIZE = 1024; | ||
| char *begin() { return &*_buf.begin(); } | ||
| char *peek() { return begin() + _readindex; } | ||
| size_t prependable() const { return _readindex; } | ||
| size_t readable() const { return _writeindex - _readindex; } | ||
| size_t writeable() const { return _buf.size() - _writeindex; } | ||
| void append(const char *data, size_t len) | ||
| { | ||
| makeSpace(len); | ||
| std::copy(data, data + len, _buf.begin() + _writeindex); | ||
| _writeindex += len; | ||
| } | ||
| // 内部腾挪 | ||
| void makeSpace(size_t len) | ||
| { | ||
| if (len > writeable()) { | ||
| if (len <= writeable() + prependable()) { | ||
| size_t readBytes = readable(); | ||
| std::copy(peek(), peek() + readBytes, begin()); | ||
| _readindex = 0; | ||
| _writeindex = _readindex + readBytes; | ||
| } else | ||
| _buf.resize(_writeindex + len); | ||
| } | ||
| } | ||
| // 返回C风格字符串 | ||
| const char *c_str() | ||
| { | ||
| makeSpace(1); | ||
| _buf[_writeindex] = '\0'; | ||
| return peek(); | ||
| } | ||
| int findStr(char *s, const char *p, size_t plen) | ||
| { | ||
| const char *pattern = std::search(s, begin() + _writeindex, p, p + plen); | ||
| return pattern == begin() + _writeindex ? -1 : pattern - s; | ||
| } | ||
| int findStr(const char *s, size_t len) | ||
| { | ||
| return findStr(peek(), s, len); | ||
| } | ||
| // 返回\r\n在Buffer中第一次出现的位置,没出现返回-1 | ||
| int findCrlf() { return findStr("\r\n", 2); } | ||
| int findLf() { return findStr("\n", 1); } | ||
| // 跳过已读的数据 | ||
| void retrieve(size_t len) | ||
| { | ||
| if (len < readable()) | ||
| _readindex += len; | ||
| else | ||
| _readindex = _writeindex = 0; | ||
| } | ||
| void retrieveAll() { retrieve(readable()); } | ||
| int readFd(int fd); | ||
| void swap(Buffer& _buffer) | ||
| { | ||
| _buf.swap(_buffer._buf); | ||
| std::swap(_readindex, _buffer._readindex); | ||
| std::swap(_writeindex, _buffer._writeindex); | ||
| } | ||
| char& operator[](size_t idx) { return _buf[idx]; } | ||
| private: | ||
| std::vector<char> _buf; | ||
| size_t _readindex = 0; | ||
| size_t _writeindex = 0; | ||
| }; | ||
|
|
||
| #endif // _ANGEL_BUFFER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #include <iostream> | ||
| #include <unistd.h> | ||
| #include <sys/poll.h> | ||
| #include <errno.h> | ||
| #include <functional> | ||
| #include <cstring> | ||
| #include "EventLoop.h" | ||
| #include "Channel.h" | ||
| #include "Buffer.h" | ||
| #include "Logger.h" | ||
|
|
||
| void Channel::changeEvent(void) | ||
| { | ||
| int evs = events(); | ||
| _loop->changeEvent(fd(), events()); | ||
| logDebug("fd(%d)'s events %s is changed to %s", eventStr(evs), | ||
| eventStr(events())); | ||
| } | ||
|
|
||
| void Channel::send(const char *s, size_t len) | ||
| { | ||
| setStatus(Channel::SENDING); | ||
| logDebug("sending to fd(%d)'s message len is %d", fd(), len); | ||
| if (!isWriting() && _output.readable() == 0) { | ||
| ssize_t n = write(fd(), s, len); | ||
| logDebug("write %zu bytes to fd(%d)", n, fd()); | ||
| if (n > 0) { | ||
| if (n < len) { | ||
| logDebug("the left %zd bytes is append to fd(%d)'s output buffer", n, fd()); | ||
| _output.append(s + n, len - n); | ||
| enableWrite(); | ||
| } else { | ||
| logDebug("the whole message is sent"); | ||
| clearStatus(Channel::SENDING); | ||
| if (_writeCompleteCb) | ||
| _writeCompleteCb(); | ||
| } | ||
| } else { | ||
| if (errno != EAGAIN | ||
| && errno != EWOULDBLOCK | ||
| && errno != EINTR) { | ||
| logWarn("%s", strerror(errno)); | ||
| handleClose(); | ||
| } | ||
| } | ||
| } else { | ||
| logDebug("the whole message %zd bytes is append to fd(%d)'s output buffer", | ||
| len, fd()); | ||
| _output.append(s, len); | ||
| } | ||
| } | ||
|
|
||
| void Channel::handleEvent(void) | ||
| { | ||
| logDebug("fd(%d)'s revents is %s", fd(), eventStr(_revents)); | ||
| // 写事件由loop自动负责 | ||
| if (_revents & POLLOUT) { | ||
| handleWrite(); | ||
| } | ||
| // 读事件由用户负责 | ||
| if (_revents & POLLIN) { | ||
| if (_readCb) _readCb(); | ||
| } | ||
| } | ||
|
|
||
| void Channel::handleAccept(void) | ||
| { | ||
| int connfd = socket().accept(); | ||
| Channel *chl = new Channel(_loop); | ||
| chl->socket().setFd(connfd); | ||
| chl->setReadCb(std::bind(&Channel::handleRead, chl)); | ||
| chl->setMessageCb(_messageCb); | ||
| _loop->addChannel(chl); | ||
| logDebug("fd(%d) is connected", connfd); | ||
| // _connectionCb() for Client | ||
| } | ||
|
|
||
| void Channel::handleRead(void) | ||
| { | ||
| ssize_t n = _input.readFd(fd()); | ||
| logDebug("read %zu bytes from fd(%d)", n, fd()); | ||
| if (n > 0) { | ||
| if (_messageCb) | ||
| _messageCb(shared_from_this(), _input); | ||
| } else if (n == 0) { | ||
| handleClose(); | ||
| } else | ||
| handleError(); | ||
| } | ||
|
|
||
| void Channel::handleWrite(void) | ||
| { | ||
| if (isWriting()) { | ||
| ssize_t n = write(fd(), _output.peek(), _output.readable()); | ||
| logDebug("write %zu bytes to fd(%d)", n, fd()); | ||
| if (n >= 0) { | ||
| _output.retrieve(n); | ||
| if (_output.readable() == 0) { | ||
| clearStatus(Channel::SENDING); | ||
| disableWrite(); | ||
| if (_writeCompleteCb) | ||
| _writeCompleteCb(); | ||
| } | ||
| } else { | ||
| if (errno == EPIPE // 对端已关闭连接 | ||
| || (errno != EAGAIN | ||
| && errno != EWOULDBLOCK | ||
| && errno != EINTR)) { | ||
| logWarn("%s", strerror(errno)); | ||
| handleClose(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void Channel::handleClose(void) | ||
| { | ||
| if (_status == Channel::SENDING) { | ||
| logDebug("the message is sending, close the connection later"); | ||
| setWriteCompleteCb(std::bind(&EventLoop::delChannel, _loop, this)); | ||
| } else | ||
| _loop->delChannel(this); | ||
| } | ||
|
|
||
| void Channel::handleError(void) | ||
| { | ||
| logWarn("fd(%d): %s", strerror(errno)); | ||
| handleClose(); | ||
| } | ||
|
|
||
| const char *Channel::eventStr(int events) | ||
| { | ||
| if (events == POLLIN) | ||
| return "POLLIN"; | ||
| else if (events == POLLOUT) | ||
| return "POLLOUT"; | ||
| else if (events == (POLLIN | POLLOUT)) | ||
| return "POLLIN | POLLOUT"; | ||
| else | ||
| return "NONE"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #ifndef _CHANNEL_H | ||
| #define _CHANNEL_H | ||
|
|
||
| #include <sys/poll.h> | ||
| #include <memory> | ||
| #include <functional> | ||
| #include "Buffer.h" | ||
| #include "Coder.h" | ||
| #include "Socket.h" | ||
| #include "Noncopyable.h" | ||
|
|
||
| class EventLoop; | ||
|
|
||
| // 不可拷贝的 | ||
| class Channel : Noncopyable, | ||
| public std::enable_shared_from_this<Channel> { | ||
| public: | ||
| typedef std::function<void(std::shared_ptr<Channel>, Buffer&)> MessageCallback; | ||
| typedef std::function<void()> ReadCallback; | ||
| typedef std::function<void()> WriteCompleteCallback; | ||
| enum { | ||
| SENDING = 001, // 正在发送消息 | ||
| }; | ||
| explicit Channel(EventLoop *loop) : _loop(loop) { } | ||
| ~Channel() { } | ||
| int fd() { return _socket.fd(); } | ||
| Socket& socket() { return _socket; } | ||
| int events() { return _events; } | ||
| void setRevents(int revents) { _revents = revents; } | ||
| int isReading() { return _events & POLLIN; } | ||
| int isWriting() { return _events & POLLOUT; } | ||
| void enableRead() { _events |= POLLIN; } | ||
| void enableWrite() { _events |= POLLOUT; changeEvent(); } | ||
| void disableWrite() { _events &= ~POLLOUT; changeEvent(); } | ||
| void changeEvent(); | ||
| void send(const char *s, size_t len); | ||
| Request& req() { return _req; } | ||
| void setStatus(int status_) { _status |= status_; } | ||
| void clearStatus(int status_) { _status &= ~status_; } | ||
| static const char *eventStr(int events); | ||
| void setReadCb(const ReadCallback _cb) | ||
| { _readCb = _cb; } | ||
| void setMessageCb(const MessageCallback _cb) | ||
| { _messageCb = _cb; } | ||
| void setWriteCompleteCb(const WriteCompleteCallback _cb) | ||
| { _writeCompleteCb = _cb; } | ||
| void handleEvent(); | ||
| void handleRead(); | ||
| void handleWrite(); | ||
| void handleClose(); | ||
| void handleError(); | ||
| void handleAccept(); | ||
| private: | ||
| EventLoop *_loop; | ||
| Socket _socket; | ||
| int _events = 0; | ||
| int _revents = 0; | ||
| int _status = 0; | ||
| Buffer _input; | ||
| Buffer _output; | ||
| // better to use boost::any | ||
| Request _req; | ||
| ReadCallback _readCb = nullptr; | ||
| MessageCallback _messageCb = nullptr; | ||
| // 通常用于保证在写完消息后再关闭连接 | ||
| WriteCompleteCallback _writeCompleteCb = nullptr; | ||
| }; | ||
|
|
||
| #endif // _CHANNEL_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是
json不够好用,还是yaml不对胃口