viewimage.php?id=2ab4c42ef0d0&no=24b0d769e1d32ca73cec8efa11d02831ed3c848cabfee483347b0fb095ab03c52ff12a3c7489994391574a3c46f2d490fd59279d3543b57f787b56b075ec091ce697


신입 들어간 회사는 네트워크 미들웨어 제품을 만듦.

회사 내에서 미들웨어의 성능을 꽤 중요시 하는데

요즘 집에서 코딩도 잘 안 하기도 해서 뭐 해볼까 생각하다가

미들웨어에 압축 기술을 집어넣으면 어떨까란 생각을 했음.

그래서 가벼운 압축 라이브러리 LZ4를 찾아서 적용해 보려 했음.

우선 미들웨어의 암호화 모듈을 참고해서 인터페이스를 짰음.

#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
typedef struct _PluginInterface {
struct{
__attribute__((cdecl)) int64_t (* before_send_message)(struct _PluginInterface* self, uintptr_t dw_handle, uintptr_t dr_handle);
__attribute__((cdecl)) int64_t (* after_write_submessage)(struct _PluginInterface* self, uintptr_t dw_handle, uintptr_t dr_handle, uint8_t* payload, int32_t length, int32_t buffer_size);
__attribute__((cdecl)) int64_t (* after_write_message)(struct _PluginInterface* self, uintptr_t dpp_guid, uint8_t* payload, int32_t length, int32_t buffer_size);
__attribute__((cdecl)) int64_t (* before_read_message)(struct _PluginInterface* self, uintptr_t dpp_guid, uintptr_t dw_handle, uintptr_t dr_handle, uint8_t* payload, int32_t length, int32_t buffer_size);
} const *const vtable;
} PluginInterface;
typedef __attribute__((cdecl)) int (*PluginInterface_create_func)(PluginInterface** out);
typedef __attribute__((cdecl)) int (*PluginInterface_delete_func)(PluginInterface* in);
#ifdef __cplusplus
}
#endif



미래에는 dll이나 so에서 함수를 동적으로 불러와서 플러그인 인터페이스만 얻을 수 있게 만들고 싶었음

인터페이스 자료형은 MS COM를 참고함.


static VTBL const vtbl = {
.before_send_process = Lz4CompressPlugin_begin_send_process,
.after_write_submessage = Lz4CompressPlugin_after_write_summessage,
.after_write_message = Lz4CompressPlugin_after_write_message,
.before_read_message = Lz4CompressPlugin_before_read_message,
};
__attribute__((cdecl))
int PluginInterface_create(PluginInterface** out) {
LZ4CompPlugin* self = (LZ4CompPlugin*)calloc(1, sizeof(LZ4CompPlugin));
self->vtable = &vtbl;
self->lz4_stream = NULL;
pthread_mutex_init(&self->mutex, NULL);
*out = (PluginInterface*)self;

return 0;
fail:
return -1;
}

생성은 적당히 하고

결론적으로 말하면

한 메시지 안에 집어넣는 서브 메시지의 수는 샘플 예제 기준으로 확실히 증가했음 대충 25%~50%정도...

그런데 메시지를 존나 빨리 보내면 갑자기 받는 쪽에서 멍청이가 되버리는 문제가 발생했음.

덕분에 샘플 예제에서 송신측에서 억지로 딜레이를 줘야 했음.