forked from scott/threaded_network_chat
Compare commits
9 Commits
37d8b7fd0f
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
| ed437d9b05 | |||
| 2c61dbcc64 | |||
| 442bc8d88f | |||
| 081a278753 | |||
| cae85a7466 | |||
| 0950342de0 | |||
| 3f899a974f | |||
| 039e9abef5 | |||
| 6bc287d6cc |
12
README.md
12
README.md
@@ -1,7 +1,13 @@
|
||||
# threaded network chat refactor
|
||||
|
||||
The code has been refactored and it compiles. Hopefully it won't explode, but that if it does, that just means we have
|
||||
actual meaningful work to do.
|
||||
The code has been refactored and it compiles. Hopefully it won't explode, but we were going to be
|
||||
doing a bunch of bug fixes anyway.
|
||||
|
||||
## What now?
|
||||
|
||||
See TODO. From here we're going to push the code to the gitlab like we were told to after everyone
|
||||
is set up. Follow the coding style guidelines because otherwise everything will be extremely gross
|
||||
and inconsistent. If you set up your editor correctly, it will take care of most of that stuff.
|
||||
|
||||
## TODO
|
||||
|
||||
@@ -16,7 +22,7 @@ actual meaningful work to do.
|
||||
## Code
|
||||
|
||||
Everything is in [src/](src).
|
||||
A mostly untouched copy of [scott's original code](https://git.therats.win/scott/threaded_network_chat) is also in [old/](old).
|
||||
A mostly untouched copy of [Scott's original code](https://git.therats.win/scott/threaded_network_chat) is also in [old/](old).
|
||||
A reformatted version of that code is also in [modified-example.cc](modified-example.cc) but it can be ignored.
|
||||
|
||||
## Build
|
||||
|
||||
7
STYLE.md
7
STYLE.md
@@ -37,7 +37,7 @@ I recommend skimming over these for inspiration.
|
||||
- return type goes on its own line,
|
||||
- function name() is on a line below that, and
|
||||
- open bracket `{` after that.
|
||||
- `for`, `if`, `while`, etc. statements that only contain one line
|
||||
- no brackets on `for`, `if`, `while`, etc. statements that only contain one line
|
||||
- Use `/* comments */` for permanent comments, `// comments` for temporary ones e.g. `TODO`'s or notices
|
||||
- **Try to make every line 100 characters wide or less.**
|
||||
- Start source files as `.cc` straight away, even if they're pure **C**.
|
||||
@@ -60,7 +60,7 @@ The length of a function name, variable name, et cetera should be directly propo
|
||||
|
||||
#### Don't
|
||||
|
||||
- abbreviate global variables,
|
||||
- abbreviate global variables **EVER**,
|
||||
- mention the data type in a variable name,
|
||||
- use a full word where an abbreviation will do
|
||||
- (especially not in a variable that will die 5 lines later),
|
||||
@@ -70,7 +70,7 @@ The length of a function name, variable name, et cetera should be directly propo
|
||||
#### Do
|
||||
|
||||
- abbreviate extremely short-lived variables to one letter,
|
||||
- e.g. `for (int index=0, index<10, i++)` -> `for (int i=0, i<10, i++)`
|
||||
- e.g. `for (int index = 0; index < 10; i++)` -> `for (int i = 0; i < 10; i++)`
|
||||
- break any rule if following it ruins the readability
|
||||
|
||||
## Source File layout
|
||||
@@ -120,4 +120,3 @@ div_numb(int n, int d)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -86,7 +86,8 @@ displayFile(string path, int startLineNum = 0, int numLines = 10)
|
||||
|
||||
// print each line directly to the screen
|
||||
int num = 0;
|
||||
while (getline(file, line) && num <= numLines + startLineNum + 1) // while there is file content and the
|
||||
while (getline(file, line) &&
|
||||
num <= numLines + startLineNum + 1) // while there is file content and the
|
||||
// line number isn't too high
|
||||
{
|
||||
if (num >= startLineNum) {
|
||||
@@ -132,7 +133,8 @@ void *
|
||||
waitForClient(void *argss)
|
||||
{
|
||||
waitClientArgs *args = static_cast<waitClientArgs *>(argss);
|
||||
clientSocketDescriptor = accept(serverSocketDescriptor, (sockaddr *)&args->newSockAddr, &args->newSockAddrSize);
|
||||
clientSocketDescriptor =
|
||||
accept(serverSocketDescriptor, (sockaddr *)&args->newSockAddr, &args->newSockAddrSize);
|
||||
if (clientSocketDescriptor >= 0) {
|
||||
writeToFile(logFileName, "client connected");
|
||||
if (linesInFile(logFileName) > LOG_LENGTH)
|
||||
@@ -184,7 +186,8 @@ setupServer(int port)
|
||||
exit(0);
|
||||
}
|
||||
// bind the socket to its local address
|
||||
int bindStatus = bind(serverSocketDescriptor, (struct sockaddr *)&servAddr, sizeof(servAddr));
|
||||
int bindStatus =
|
||||
bind(serverSocketDescriptor, (struct sockaddr *)&servAddr, sizeof(servAddr));
|
||||
if (bindStatus < 0) {
|
||||
// keeps from bricking the terminal if this happens
|
||||
endwin();
|
||||
@@ -288,7 +291,8 @@ setupClient()
|
||||
sendSockAddr.sin_port = htons(PORT_NUM);
|
||||
clientSocketDescriptor = socket(AF_INET, SOCK_STREAM, 0);
|
||||
// try to connect...
|
||||
int status = connect(clientSocketDescriptor, (sockaddr *)&sendSockAddr, sizeof(sendSockAddr));
|
||||
int status =
|
||||
connect(clientSocketDescriptor, (sockaddr *)&sendSockAddr, sizeof(sendSockAddr));
|
||||
if (status < 0)
|
||||
writeToFile(logFileName, "Error connecting to socket!");
|
||||
writeToFile(logFileName, "Connected to the server!");
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
@@ -36,6 +35,7 @@ std::string log_path;
|
||||
int socket_descriptor_server;
|
||||
int socket_descriptor_client;
|
||||
|
||||
/* We use this for both. Probably won't be like this forever. */
|
||||
pthread_t client_wait_thread;
|
||||
|
||||
int
|
||||
|
||||
@@ -32,7 +32,8 @@ typedef struct __wserver_args_t {
|
||||
std::string log;
|
||||
} wserver_args_t;
|
||||
|
||||
/* client_start(listen_ip, listen_port, &socket_descriptor_client, log_path, &client_wait_thread);
|
||||
/*
|
||||
* client_start(listen_ip, listen_port, &socket_descriptor_client, log_path, &client_wait_thread);
|
||||
*/
|
||||
void
|
||||
client_start(std::string ip, int port, int *sock, std::string log, pthread_t *thr)
|
||||
|
||||
Reference in New Issue
Block a user