Skip to content

Commit 18ad864

Browse files
author
dfurneau
committed
Fixed issue with Buffer size in recv, fixed atomic include in threads, added an initializer to Parse in main.cpp
1 parent f9efe51 commit 18ad864

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: dfurneau <dfurneau@student.42abudhabi.ae> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2023/03/07 07:25:25 by dfurneau #+# #+# #
9-
# Updated: 2023/04/14 01:22:44 by dfurneau ### ########.fr #
9+
# Updated: 2023/04/15 00:52:29 by dfurneau ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -20,7 +20,7 @@ SSRCS = ./src/main.cpp \
2020
SOBJS = ${SSRCS:.cpp=.o}
2121
CXX = g++
2222

23-
CXXFLAGS = -Wall -Wextra -Werror -std=c++2a
23+
CXXFLAGS = -Wall -Wextra -Werror -std=c++2a -Ofast
2424

2525
LIBS = -pthread
2626

includes/client-tester.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
/* By: dfurneau <dfurneau@student.42abudhabi.ae> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/03/14 10:12:49 by dfurneau #+# #+# */
9-
/* Updated: 2023/04/14 00:28:28 by dfurneau ### ########.fr */
9+
/* Updated: 2023/04/15 00:40:11 by dfurneau ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#ifndef CLIENT_TESTER_HPP
1414
# define CLIENT_TESTER_HPP
1515

16+
# define BUFFSIZE 4095
1617
# include "parse.hpp"
1718

1819
# include <cstring>

includes/thread.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: dfurneau <dfurneau@student.42abudhabi.ae> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/12 02:57:16 by dfurneau #+# #+# */
9-
/* Updated: 2023/04/14 00:24:52 by dfurneau ### ########.fr */
9+
/* Updated: 2023/04/15 00:47:12 by dfurneau ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -17,7 +17,10 @@
1717
# include "parse.hpp"
1818

1919
# include <mutex>
20+
# include <atomic>
2021
# include <thread>
22+
# include <string>
23+
# include <iostream>
2124
# include <csignal>
2225

2326
inline std::mutex mtx;

src/client-tester.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: dfurneau <dfurneau@student.42abudhabi.ae> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/03/14 10:12:40 by dfurneau #+# #+# */
9-
/* Updated: 2023/04/14 00:27:17 by dfurneau ### ########.fr */
9+
/* Updated: 2023/04/15 00:40:01 by dfurneau ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -157,10 +157,13 @@ void clientTester::ircconnect( void ) {
157157
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
158158
}
159159

160-
char buffer[1024];
160+
char buffer[BUFFSIZE];
161161
ssize_t byteRec;
162162

163-
while ( ( byteRec = recv( m_fd, &buffer, std::strlen( buffer ), 0 ) ) <= 0) ;
163+
while ( ( byteRec = recv( m_fd, &buffer, BUFFSIZE, 0 ) ) <= 0) {
164+
if ( byteRec > 0 )
165+
std::cout << buffer << std::endl;
166+
}
164167

165168
for ( std::vector<std::string>::const_iterator it = m_data->m_afterConnect.begin(); it != m_data->m_afterConnect.end(); ++it ) {
166169
ircsend( replaceBuffer( *it ) );

src/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: dfurneau <dfurneau@student.42abudhabi.ae> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/03/14 10:12:40 by dfurneau #+# #+# */
9-
/* Updated: 2023/04/14 00:39:19 by dfurneau ### ########.fr */
9+
/* Updated: 2023/04/15 00:51:59 by dfurneau ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -82,14 +82,15 @@ int main( int ac, char** av ) {
8282
if ( threadCount <= 0 || !isValidIp( ipAddress ) || ( port <= 0 || port >= 65535 ) )
8383
return usage( av[0] );
8484

85-
Parse* p;
85+
Parse* p = nullptr;
8686
try {
8787
p = new Parse( "./conf/replace.conf", "./conf/connect.conf", "./conf/after-connect.conf", "./conf/disconnect.conf", "./conf/loop.conf" );
8888
p->init( );
8989
}
9090
catch ( std::runtime_error& ex ) {
9191
std::cout << "Conf files missing from ./conf directory" << std::endl;
92-
delete p;
92+
if ( p )
93+
delete p;
9394
return EXIT_FAILURE;
9495
}
9596

0 commit comments

Comments
 (0)