๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“– C๋ž‘ C++

(15)
Boost๋กœ ์‹œ๊ฐ„ ๊ฐ’ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ Boost๋กœ ์‹œ๊ฐ„ ๊ฐ’ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ๊ฐœ๋ฐœ์„ ํ•˜๋‹ค๋ณด๋ฉด, ๋กœ๊ทธ๋ผ๋˜๊ฐ€ HTTP ์š”์ฒญ์„ ๋ฐ›์•˜์„ ๋•Œ๋ผ๋˜๊ฐ€ ํ˜„์žฌ ์‹œ๊ฐ„์„ ์ •๋ณด๋ฅผ ๋‚จ๊ธธ ๋•Œ๊ฐ€ ์ข…์ข… ์žˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” C์–ธ์–ด์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ˜„์žฌ ์‹œ๊ฐ„์„ ๋‚จ๊ธฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค long get_current_msec(void) { long cur_msec = 0; struct timeval tv_time; gettimeofday(&tv_time, 0); cur_msec = (long)(tv_time.tv_sec*1000) + (long)(tv_time.tv_usec/1000); return cur_msec; } Boost์—์„œ๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์—ญ์‹œ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค (๋ฌผ๋ก  ์œ„ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ C++ ์ฝ”๋“œ์— ์ ์šฉํ•ด๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค ๐Ÿ˜Š ) Boost์˜ Posix Time ์†Œ๊ฐœ๊ธ€์—๋Š” ์•„..
Boost::program_options ์‚ฌ์šฉ๊ธฐ ์˜ค๋Š˜์€ ์•„์นจ๋ถ€ํ„ฐ ์ผ์ด ์ž˜ ๋˜์ง€ ์•Š๋Š”๋‹ค ๋จธ๋ฆฌ๊ฐ€ ์ž˜ ์•ˆ ๋Œ์•„๊ฐ€์„œ ๋ง‰๋ง‰ํ•œ ๋Š๋‚Œ ใ… .,ใ…œ ๊ทธ๋ž˜์„œ~~ ๊ธฐ๋ถ„ ์ „ํ™˜ ์šฉ์œผ๋กœ ๊ธ€ ํ•˜๋‚˜ ์Œˆ๋ฐ•ํ•˜๊ฒŒ ์˜ฌ๋ฆฌ๊ณ  ๋‹ค์‹œ ์—ด์ผ ํ•ด๋ณด๊ฒ ๋‹ค ์ด์ „์— ์ž‘์„ฑํ•œ boost ๊ด€๋ จ ๊ธ€์—๋„ ์ผ๋‹ค์‹œํ”ผ ๋‚˜๋Š” boost์— ๋งŽ์€ ๊ณ ๋งˆ์›€์„ ๋Š๋‚€๋‹ค +_+ ์—ฅ ์ด๊ฒŒ ์žˆ๋‹ค๊ณ ? ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋งŽ๊ธฐ ๋•Œ๋ฌธ ์ด๋ฒˆ์— ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ์ž‘์„ฑํ•  ๊ฒŒ ์žˆ์–ด์„œ C๋กœ ํ•˜๋ ค๋‹ค๊ฐ€ C++๋กœ ํ•˜๋ ค๋Š”๋ฐ ์„ธ์ƒ์—.. Boost์—๋Š” program options๋ผ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ด์„œ argument ๊ธฐ๋Šฅ์„ ์ฐธ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ๋†“์•˜๋‹ค 1. ๊ธด ์„œ๋ก  ์šฐ๋ฆฌ๊ฐ€ ์–ด๋–ค ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•  ๋•Œ, ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์‹คํ–‰์„ ํ•ด๋ณธ ๊ฒฝํ—˜์ด ์žˆ์„ ๊ฒƒ์ด๋‹ค argument๋ฅผ ํ”„๋กœ์„ธ์Šค ์‹คํ–‰ ํŒŒ์ผ ๋’ค์— ์ถ”๊ฐ€ํ•ด์„œ ์‚ฌ์šฉํ•˜๊ณค ํ•˜๋Š”๋ฐ $ gcc --help Usage: gcc [opt..
์ „์ฒ˜๋ฆฌ๊ธฐ(preprocessor)์™€ ๋งคํฌ๋กœ(macro) C/C++์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ define์œผ๋กœ ์ƒ์ˆ˜๋‚˜ ๋ฌธ์ž์—ด์„ ์ •์˜ํ•ด๋ณธ ์ ์ด ํ•œ ๋ฒˆ์ฏค์€ ์žˆ์„ ๊ฒƒ์ด๋‹ค #include #define MAX_SIZE 1024 #define MAIN_NAME "test main" using namespace std; int main(void) { cout
Error ํ•ด๊ฒฐ: boost::shared_ptr<boost::asio::io_context>::operator* boost thread๋ฅผ ํ™œ์šฉํ•˜์—ฌ io_context_pool์„ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•˜๋˜ ์ค‘.. core๊ฐ€ ๋‚ฌ๋‹ค ์ด์   ๋†€๋ž์ง€๋„ ์•Š์€.. ์ฐธ๊ณ ํ•œ ThreadPool ์˜ˆ์‹œ๋Š” ์•„๋ž˜์— ์ฒจ๋ถ€ ๋งํฌ๋กœ ์˜ฌ๋ ค๋‘๊ฒ ๋‹ค CMD> ./process ... /usr/include/boost/smart_ptr/shared_ptr.hpp:728: typename boost::detail::sp_derr::operator*() const [with T = boost::asio::io_context; typename boost::deta_context&]: Assertion `px != 0' failed. Aborted (core dumped) ๊ทธ๋Ÿฌ๋‹ค ๋น„์Šทํ•œ ์—๋Ÿฌ๋ฅผ ๊ฐ€์ง„ stack overflow ๊ธ€์„ ๋ณด์•˜๋Š”๋ฐ ๋‚ด์šฉ์€ ์ด๋Ÿฌํ–ˆ๋‹ค ์ผ๋‹จ ์›์ธ์€,..
STRUCT์™€ UNION์„ ์•Œ์•„๋ณด์ž STUCT(๊ตฌ์กฐ์ฒด)์™€ UNION(๊ณต์šฉ์ฒด)์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌถ์Œ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ž๋ฃŒ๊ตฌ์กฐ๋‹ค ์ •์˜ ๋ฐฉ๋ฒ•๋„ ๋น„์Šทํ•˜๊ณ  ์‚ฌ์šฉ ์ด์œ ๋„ ๊ฐ™์ง€๋งŒ, ๋‘˜์˜ ์ฐจ์ด์ ์€ ๋ฉ”๋ชจ๋ฆฌ ์ ์žฌ ๋ฐฉ์‹์ด๋‹ค ๋ฉ”๋ชจ๋ฆฌ์— ์–ด๋–ป๊ฒŒ ์Œ“์ด๊ธธ๋ž˜ ๋‹ค๋ฅธ์ง€์™€ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๊ฐ„๋‹จํžˆ ์ •๋ฆฌํ•˜๊ฒ ๋‹ค ** ๋ฉ”๋ชจ๋ฆฌ ๋ฌถ์Œ ํƒ€์ž… ** C - STRUCT์™€ UNION ์ œ๊ณต C++ - Class, STRUCT, UNION ์ œ๊ณต 1. STRUCT์™€ UNION ์‚ฌ์šฉ ๋ฐฉ๋ฒ• (1) STRUCT (๊ตฌ์กฐ์ฒด) ์‚ฌ์šฉ struct๋ผ๋Š” ๋‹จ์–ด์— ์ƒ์†Œํ•ดํ•  ํ•„์š”๋Š” ์—†๋‹ค int, charํ˜• ๋“ฑ์˜ ๋ฐ์ดํ„ฐ ํ˜•๊ณผ ๊ฒฐ๊ตญ์—๋Š” ๊ฐ™๋‹ค ใ…‡ใ…‡ STRUCT์˜ ํŠน์ง• - ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์ฑ„๋กญ๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค - ๋ฐ์ดํ„ฐํ˜•์˜ ์—ญํ• ์ด๋‹ค - ๊ตฌ์กฐ์ฒด ์ด๋ฆ„ ์ง€์„ ๋•Œ๋Š” C ๋ช…๋ช… ๊ทœ์น™ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹๋‹ค - ๊ตฌ์กฐ์ฒด ํ™•์žฅ ๊ฐœ๋… → Class (C++์—์„œ)..
C++ ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ๋ฅผ ์•Œ์•„๋ณด์ž - (2) shared_ptr ์˜ค๋Š˜์€ ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ ์ค‘... ๋‘ ๋ฒˆ์งธ์ธ shared_ptr์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณผ๊ฑฐ๋‹ค ์š”์ฆ˜ ๋„ค์ด๋ฒ„ ๋ธ”์ฑŒ ์ด๋ฒคํŠธ๋ฅผ ํ•˜๊ณ  ์žˆ๋Š”๋ฐ ๊ฐ€์šด๋ฐ ์ •๋ ฌ๋กœ ํ•˜๋‹ˆ๊นŒ ์‚ฌ์ง„ ์ฒจ๋ถ€ํ•˜๊ธฐ๊ฐ€ ๋„ˆ๋ฌด ์ข‹์•˜์–ด์„œ ์™ผ์ชฝ์ •๋ ฌํŒŒ์˜€๋Š”๋ฐ ๋ฐ”๊ฟ” ๋ณด๋ ค๊ณ  ํ•œ๋‹ค ^_^ ++ ์ด์ „ ๊ธ€ ์˜ฌ๋ฆฌ๊ณ  ๋‹ค์Œ ๋‚  ์˜ฌ๋ฆด๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ๋‹ค๋ฅธ๊ฑธ ๋จผ์ € ์˜ฌ๋ ธ๋”๋‹ˆ ์žŠํ˜€์งˆ ๋ป” ํ–ˆ๋‹ค 1. ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ์—๋Š” ๋ญ๊ฐ€ ์žˆ์ง€? ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ๋Š” 3๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค 1) unique_ptr 2) shared_ptr (์˜ค๋Š˜ํ• ๊ฑฐ) 3) weak_ptr 1-1) unique_ptr์ด ๋ญ์˜€๋”๋ผ (๋งํฌ ์ฒจ๋ถ€ ^^) ์ฒซ ๋ฒˆ์งธ, unique_ptr์€ ํฌ์ธํ„ฐ๋ฅผ ํ†ตํ•ด Uniqueํ•œ ์†Œ์œ ๊ถŒ์„ ๊ฐ€์ง€๊ณ  unique_ptr ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚  ๋•Œ ํ•ด๋‹น ๊ฐœ์ฒด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ์ด๋‹ค ๋‘ ๋ฒˆ์งธ, make_unique() ๋˜๋Š” new๋ฅผ ์‚ฌ..
Error ํ•ด๊ฒฐ: undefined reference to `vtable for XXX' undefined reference to `vtable for XXX' collect2: error: ld returned 1 exit status ... ์ด๋ ‡๊ฒŒ ์—๋Ÿฌ๊ฐ€ ๋‚˜์˜จ๋‹ค๋ฉด ์•„๋งˆ vtable for {ํด๋ž˜์Šค ๋ช…} ์ด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋ ํ…๋ฐ ๊ตฌํ˜„ํ•˜๋ ค๋Š” ํด๋ž˜์Šค์— ํ˜น์‹œ virtual ํ•จ์ˆ˜๋ฅผ ๋ช…์‹œํ•˜๊ณ ์„œ ์†Œ์ŠคํŒŒ์ผ์—์„œ ๊ตฌํ˜„์„ ์•ˆํ–ˆ๋Š”์ง€ ํ™•์ธํ•˜๋„๋ก ๋˜๋Š”, ๋ถ€๋ชจ ํด๋ž˜์Šค์—์„œ virtual ๋ช…์‹œํ•ด๋‘”๊ฒŒ ์žˆ๋Š”๋ฐ ์ƒ์†ํ•˜๋‹ค๊ฐ€ ์‚ฌ์šฉ ์•ˆํ–ˆ๋Š”์ง€ ํ™•์ธ
Boost-echo tcp client & server๋ฅผ ์‚ดํŽด๋ณด์ž (1) Boost๋Š” C++์„ ํ•˜๋‹ค๋ณด๋ฉด ์–ธ์  ๊ฐ„ ๋ฐ˜๋“œ์‹œ ๊ผญ ์‚ฌ์šฉํ•˜๊ฒŒ๋  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค Boost์— ๋Œ€ํ•œ ์„ค๋ช…์€ ์•„๋ž˜์— ์ฒจ๋ถ€ํ•  Boost ๊ณต์‹ํ™ˆํŽ˜์ด์ง€์—์„œ ํ•œ๋ฒˆ ์ฝ์–ด๋ณด๋Š”๊ฑธ ์ถ”์ฒœํ•œ๋‹ค (์žฌ๋ฐŒ์Œ) ์ฒ˜์Œ์— boost๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š”, STL(Standard Template Library)์ด๋ž‘ ์—ญํ• ์ด ๊ฐ™์€ ๊ฒƒ ๊ฐ™์€๋ฐ, ์™œ ์“ฐ์ง€? ํ–ˆ๋Š”๋ฐ STL์„ ํ™œ์šฉํ•ด์„œ ๋ญ”๊ฐ€ ์ข€๋” ํ•ด์•ผํ•  ๋•Œ, boost์—๋Š” ์ด๋ฏธ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ๋งŽ์ด ์žˆ์—ˆ๋‹ค ์˜ˆ์ œ ํ™œ์šฉํ•ด์„œ ์“ฐ๋‹ค๋ณด๋ฉด ๊ธˆ๋ฐฉ ์ต์ˆ™ํ•ด์งˆ ์ˆ˜ ์žˆ๋‹น ์„œ๋ก ์ด ๊ธธ์—ˆ๋Š”๋ฐ, Boost ํ™œ์šฉ์„ ์ข€ ๋” ์ž˜ํ•ด๋ณด๊ธฐ ์œ„ํ•ด์„œ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ƒ˜ํ”Œ ์ฝ”๋“œ๋ฅผ ํ•œ๋ฒˆ์”ฉ ๊ณต๋ถ€ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค ์‹ค์ œ ํ™œ์šฉํ•  ๋•Œ ๋†“์นœ ๋ถ€๋ถ„ ํ™•์ธ๋„ ํ• ๊ฒธใ…‹ Boost Asio์— ๋Œ€ํ•œ ์„ค๋ช…์€ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜๊ธธ ๋ฐ”๋ž€๋‹ค ์ฒซ ๋ฒˆ์งธ๋กœ ํ™•์ธํ•œ ์˜ˆ์ œ๋Š” Async TCP Server์™€ Cl..