Compare commits

9 Commits

Author SHA1 Message Date
ed437d9b05 ugh 2 2026-03-09 13:26:51 -05:00
2c61dbcc64 ugh 2026-03-09 13:26:08 -05:00
442bc8d88f EVEN FURTHER BIKESHEDDING 2026-03-09 13:23:13 -05:00
081a278753 even further bikeshedding 2026-03-09 13:20:40 -05:00
cae85a7466 remove unnecessary include 2026-03-09 13:15:39 -05:00
0950342de0 ok now im done 2026-03-09 13:08:09 -05:00
3f899a974f very formatting stuff 2026-03-09 13:05:32 -05:00
039e9abef5 update modified-example.cc to match new column limit 2026-03-09 13:00:46 -05:00
6bc287d6cc update README.md 2026-03-09 12:59:55 -05:00
5 changed files with 24 additions and 14 deletions

View File

@@ -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

View File

@@ -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)
}
```

View File

@@ -86,8 +86,9 @@ 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
// line number isn't too high
while (getline(file, line) &&
num <= numLines + startLineNum + 1) // while there is file content and the
// line number isn't too high
{
if (num >= startLineNum) {
move(lineNum, 0);
@@ -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!");

View File

@@ -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

View File

@@ -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)