프로그래밍
-
error_code 정의 참고 코드 조각프로그래밍/코드 조각 2018. 10. 28. 00:59
enum class VerificationErrc{ //Algorithms provided does not match with header InvalidAlgorithm = 1, //Token is expired at the time of decoding TokenExpired, //The issuer specified does not match with payload InvalidIssuer, //The subject specified does not match with payload InvalidSubject, //The field IAT is not present or is of invalid type InvalidIAT, //Checks for the existence of JTI //if val..
-
c++에서의 패킷 핸들러 바인딩프로그래밍/코드 조각 2018. 10. 21. 23:43
#include #include #include using namespace std; namespace packet{ enum class Type : unsigned short { None = 0, Login = 1, Logout = 2, }; struct Header { std::uint16_t size; Type type; }; struct Login { char id[20]; std::uint8_t len; };} std::map handlers; template void bind(packet::Type type, void(*handler)(int, const PayloadType&)){ handlers[type] = [handler](int network..
-
Visual Studio 사용자 정의 빌드로 proto 파일 빌드하기프로그래밍 2018. 10. 12. 22:50
파일의 속성 페이지에서 일반-항목 형식에서 사용자 지정 빌드 도구 선택 명령줄과 출력 지정한다. 명령줄은 cmd에서 컴파일러를 실행하는 것처럼 설정해주면 된다. $(ProjectDir), %(Filename) 같은 비주얼 스튜디오에서 제공하는 매크로를 이용하면 편하다. 출력엔 사용자 정의 빌드로 인해 만들어지는 써주면 된다.프로토콜 버퍼 컴파일러에서 c++로 출력을 할 경우, 헤더와 cc파일이 만들어지기 때문에 2개를 지정했다.(각 파일의 구분은 ;로) 설정을 마치고 빌드하면 결과물이 나온다. 출력파일 지정의 의미프로젝트를 빌드할 때 출력으로 지정된 파일이 없다면 해당 파일에 대해서 컴파일을 실행한다.프로젝트를 정리하면 출력으로 지정된 파일들이 제거된다. 샘플 프로젝트:
-
::operator new, ::operator delete프로그래밍/c++ 2018. 10. 3. 15:25
c++에서 생성자 호출 없는 new를 찾다가 알게되었다.(c의 malloc과 같은 기능이지만)::operator new, ::operator delete는 c의 malloc과 free 처럼 사용할 수 있다. #include struct foo{ foo(){} ~foo(){}}; int main(){ foo* p = static_cast(::operator new(sizeof foo)); // 메모리 할당 new (p)foo(); // replacement new p->~foo(); // 소멸자 호출 ::operator delete(p); // 메모리 해제 return 0;}
-
c++ 클래스 상속 관계에서의 메모리 정렬프로그래밍/c++ 2018. 9. 16. 20:27
https://stackoverflow.com/questions/2006504/c-data-alignment-member-order-inheritance 0. 상속 관계일 때 베이스 클래스의 멤버 변수의 메모리 위치class base { int i; }; class derived : public base // same for private inheritance { int k; };일 때int i; // baseint k; // derived 순서로 정렬 됨 1. 거의 모든 컴파일러는 클래스의 나머지 멤버 앞에 가상 테이블 포인터를 배치합니다. 즉, vftable 포인터와 클래스 멤버 사이에 약간의 패딩이있을 수 있습니다.
-
enable_shared_from_this를 사용했는데 예외가 발생한 경우프로그래밍/의문 2018. 9. 13. 00:22
class session : std::enable_shared_from_this{public: session(tcp::socket socket) : socket(std::move(socket)){} //...}; void do_accept() { acceptor.async_accept(socket, [&](auto error) { if (error) { return; } std::shared_ptr newSession = std::make_shared(std::move(socket)); newSession->run(); do_accept(); }); } void do_receive(){ auto self = shared_from_this(); socket.async_receive(asio::buffer(..