Skip to content

Commit ddcb147

Browse files
P3 completed and tested
1 parent d52ec98 commit ddcb147

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

P3/msgq_client.c

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ int main() {
183183
size_t alias_len = getline(&user_name, &max_name_len, stdin);
184184
user_name[alias_len - 1] = '\0';
185185

186+
if(strcmp(user_name, "server") == 0) {
187+
err_exit("Error: Username cannot be \"server\". Exiting...\n");
188+
_exit(EXIT_SUCCESS);
189+
}
190+
186191
if (pthread_mutex_init(&lock, NULL) != 0) {
187192
err_exit("\n Error Mutex init. Exiting...\n");
188193
}

P3/msgq_server.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int get_old_msg(OLD_MSG * old_msg, size_t pos) {
5656
if (old_msg->n_msg == 0)
5757
return -1;
5858

59-
return (old_msg->start_ptr + pos - 1) % MAX_OLD_MSG;
59+
return (old_msg->start_ptr + pos) % MAX_OLD_MSG;
6060
}
6161

6262
int add_old_msg(OLD_MSG * old_msg, MSG * msg) {
@@ -217,7 +217,6 @@ int send_group_msg(MSG * msg) {
217217

218218
msg->time = time(NULL);
219219
add_old_msg(&(grp->old_msg), msg);
220-
printf("%ld\n", grp->old_msg.n_msg);
221220
return 0;
222221
}
223222

0 commit comments

Comments
 (0)