ACE_Select_Reacot를 ACE_Reactor::instance 에 적용예제
윈도우에서 ACE책 예제(ACE 프로그래머 가이드, C++ NetworkProgramming Volum1, 2)에 나온 소스를 볼때 Select_Reactor로 적용하는것이 작동을 원할하게 할수 있다.


#include "ace/Select_Reactor.h"
#include "ace/Reactor.h"

int ACE_TMAIN( int , ACE_TCHAR * [] )
{
    ACE_Select_Reactor * ps = new ACE_Select_Reactor;

    // 두번째 인자를 true로 하면 Reactor가 삭제될때 첫번째 인자로 넘긴 Reactor를 자동삭제 된다.
    ACE_Reactor * pr = new ACE_Reactor( ps, true );

    // 두번째 인자를 true로 하면 Reactor가 삭제될때 첫번째 인자로 넘긴 Reactor를 자동삭제 된다.
    ACE_Reactor::instance( pr, true );
    ...
    ...

    ACE_Reactor::instance()->run_reactor_event_loop();

    return 0;
}
링크 에러

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

해결책
환경 설정  --> Linker --> Input -->Ignore Specific Library

msvcrt.lib

입력 후 리빌드.

Tip : 링커 command line 에 /VERBOSE:LIB 를 추가하면 링커가 검색중인 라이브러리가 보인다.

아래 처럼 Visual Studio 2008 에서

솔류션 탐색기에 현재 편집중인 파일위치를 알수 있게 해준다.

지인 사이트 KeyTol 블로그 에서 발췌하였다^^




옵션은 아래를 참고^^


Task 구현
class LogTest_Task : public ACE_Task<ACE_NULL_SYNCH>
{
	typedef ACE_Task<ACE_NULL_SYNCH>	super;
private:
	ACE_Log_Msg_Callback * m_pLogCallback;

public:
	LogTest_Task( ACE_Log_Msg_Callback * logCallback )	:
		super(),
		m_pLogCallback( logCallback )
	{
	}

	virtual int		svc()
	{
		if( m_pLogCallback )
		{
			ACE_LOG_MSG->set_flags( ACE_Log_Msg::MSG_CALLBACK );
			ACE_LOG_MSG->clr_flags( ACE_Log_Msg::STDERR );
			ACE_LOG_MSG->msg_callback( m_pLogCallback );
		}

		// Log 출력.
		ACE_DEBUG( ( LM_DEBUG,
					ACE_TEXT("DEBUG hello World") ) );
		ACE_ERROR( ( LM_ERROR,
					ACE_TEXT("ERROR hello World") ) );	
		return 0;

	}

};


호출
// Task생성및 Task 실행.
LogTest_Task	logTask( ACE_Log_Msg::instance()->msg_callback() );
logTask.activate();
logTask.wait();
추가된소스
BOOL CACE_MFCApp::InitInstance()
{
        .....

        /////////////////////////////////////////////////////////////////
        // 추가
        WORD                    wVersionRequested;
        WSADATA                 wsaData;
        int             err = 0;

        wVersionRequested = MAKEWORD( 2, 2 );
        if( WSAStartup( wVersionRequested, &wsaData ) != 0 )
                return FALSE;

        ACE::init();
        /////////////////////////////////////////////////////////////////

        CACE_MFCDlg dlg;
        m_pMainWnd = &dlg;
        INT_PTR nResponse = dlg.DoModal();
        if (nResponse == IDOK)
        {
                // TODO: Place code here to handle when the dialog is
                //  dismissed with OK
        }
        else if (nResponse == IDCANCEL)
        {
                // TODO: Place code here to handle when the dialog is
                //  dismissed with Cancel
        }

        /////////////////////////////////////////////////////////////////
        // 추가
        ACE::fini();
        WSACleanup( );
        /////////////////////////////////////////////////////////////////

        // Since the dialog has been closed, return FALSE so that we exit the
        //  application, rather than start the application's message pump.
        return FALSE;
}

간단하게 디렉토리를 압축할수 있게하는 라이브러리이다.

http://joyholic.kr/trackback/32


위 사이트를 참고하여
Zlib( http://www.winimage.com/zLibDll/index.html )
MiniZip( http://www.winimage.com/zLibDll/minizip.html )
zipunzip 라이브러리( http://www.codeproject.com/KB/cpp/zipunzip.aspx )

사이트에 가서 해당 소스를 가져와 소스를 합치고 해서 visual c++ 2008에서 컴파일 했다.

파일은 두개인데
한개는 ZipUnzip 라이브러리 파일이고
한개는 ZipUnzip라이브러리를 사용한 샘플파일( 위사이트에서 참고한 파일 )이다.

사용법은 아래와 같다.


// DirectoryZip  --- c:\tmp 디렉토리를 c:\tmp.zip 으로 압축
        CZipper zip;

        if (zip.OpenZip("c:\\tmp.zip", false))
                zip.AddFolderToZip("c:\\tmp", false);

// FileZip --- c:\tmp\test.txt 파일을 c:\tmp.zip 으로 압축
        CZipper zip;

        if (zip.OpenZip("c:\\tmp.zip", false))
                zip.AddFileToZip("c:\\tmp\\text.txt", false);

// Unzip --- c:\tmp.zip 을 c:\tmp에 압축해제
        CUnzipper uz;
        bool br = uz.OpenZip("c:\\tmp.zip");
        if(br)
                br = uz.UnzipTo("c:\\tmp");
아래 샘플 코드의 실행 방법은 인자를 붙여 실행합니다.
 ZipUnzip.exe c C:\tmp  ==> c:\tmp 디렉토리를 압축하여 c:\tmp.zip 파일을 만든다.
 ZipUnzip.exe d C:\tmp ==> c:\tmp.zip 파일을 압축해제하여 c:\tmp에 압축을 푼다.

압축을 해제할때 필요.

예제 소스
http://www.opensource.apple.com/source/gcc3/gcc3-1161/fastjar/dostime.c

/*
  dostime.c - routines for converting UNIX time to MS-DOS time.  

  Borrowed from Info-zip's unzip

  Copyright (C) 1999 Bryan Burns

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

/* $Id: dostime.c,v 1.3 2001/09/17 20:35:55 zlaski Exp $

   $Log: dostime.c,v $
   Revision 1.3  2001/09/17 20:35:55  zlaski
   Resolve conflicts due to 2001-09-12 FSF import.

   Revision 1.2  2000/12/14 18:45:35  ghazi
   Warning fixes:

   	* compress.c: Include stdlib.h and compress.h.
   	(rcsid): Delete.
   	(report_str_error): Make static.
   	(ez_inflate_str): Delete unused variable.  Add parens in if-stmt.
   	(hrd_inflate_str): Likewise.

   	* compress.h (init_compression, end_compression, init_inflation,
   	end_inflation): Prototype void arguments.

   	* dostime.c (rcsid): Delete.

   	* jargrep.c: Include ctype.h, stdlib.h, zlib.h and compress.h.
   	Make functions static.  Cast ctype function argument to `unsigned
   	char'.  Add parens in if-stmts.  Constify.
   	(Usage): Change into a macro.
   	(jargrep): Remove unused parameter.

   	* jartool.c: Constify.  Add parens in if-stmts.  Align
   	signed/unsigned char pointers in functions calls using casts.
   	(rcsid): Delete.
   	(list_jar): Fix printf format specifier.
   	(usage): Chop long string into bits.  Reformat.

   	* pushback.c (rcsid): Delete.

   Revision 1.1  2000/12/09 03:08:23  apbianco
   2000-12-08  Alexandre Petit-Bianco  < apbianco@cygnus.com >

           * fastjar: Imported.

   Revision 1.1.1.1  1999/12/06 03:09:12  toast
   initial checkin..



   Revision 1.6  1999/05/10 08:32:26  burnsbr
   added dos2unixtime

   Revision 1.5  1999/04/27 10:03:50  burnsbr
   configure support

   Revision 1.4  1999/04/26 21:55:19  burnsbr
   switched from sys/time.h to time.h for better portability

   Revision 1.3  1999/04/20 08:54:30  burnsbr
   added GPL comment

   Revision 1.2  1999/04/20 05:10:53  burnsbr
   added RCS tags


*/
#include "config.h"

#ifdef TM_IN_SYS_TIME
#include < sys/time.h >
#else
#include < time.h >
#endif

#include "dostime.h"

/*

 Copyright (C) 1990-1997 Mark Adler, Richard B. Wales, Jean-loup Gailly,
 Kai Uwe Rommel, Onno van der Linden and Igor Mandrichenko.
 Permission is granted to any individual or institution to use, copy, or
 redistribute this software so long as all of the original files are included,
 that it is not sold for profit, and that this copyright notice is retained.

*/


time_t dos2unixtime(dostime)
     unsigned long dostime;            /* DOS time to convert */
     /* Return the Unix time_t value (GMT/UTC time) for the DOS format (local)
      * time dostime, where dostime is a four byte value (date in most
      * significant word, time in least significant word), see dostime() 
      * function.
      */
{
  struct tm *t;         /* argument for mktime() */
  time_t clock = time(NULL);

  t = localtime(&clock);
  t->tm_isdst = -1;     /* let mktime() determine if DST is in effect */
  /* Convert DOS time to UNIX time_t format */
  t->tm_sec  = (((int)dostime) <<  1) & 0x3e;
  t->tm_min  = (((int)dostime) >>  5) & 0x3f;
  t->tm_hour = (((int)dostime) >> 11) & 0x1f;
  t->tm_mday = (int)(dostime >> 16) & 0x1f;
  t->tm_mon  = ((int)(dostime >> 21) & 0x0f) - 1;
  t->tm_year = ((int)(dostime >> 25) & 0x7f) + 80;

  return mktime(t);
}

unsigned long dostime(y, n, d, h, m, s)
int y;                  /* year */
int n;                  /* month */
int d;                  /* day */
int h;                  /* hour */
int m;                  /* minute */
int s;                  /* second */
/* Convert the date y/n/d and time h:m:s to a four byte DOS date and
   time (date in high two bytes, time in low two bytes allowing magnitude
   comparison). */
{
  return y < 1980 ? dostime(1980, 1, 1, 0, 0, 0) :
    (((unsigned long)y - 1980) << 25) | ((unsigned long)n << 21) | 
    ((unsigned long)d << 16) | ((unsigned long)h << 11) | 
    ((unsigned long)m << 5) | ((unsigned long)s >> 1);
}


unsigned long unix2dostime(t)
time_t *t;             /* unix time to convert */
/* Return the Unix time t in DOS format, rounded up to the next two
   second boundary. */
{
  time_t t_even;
  struct tm *s;         /* result of localtime() */

  t_even = (*t + 1) & (~1);     /* Round up to even seconds. */
  s = localtime(&t_even);       /* Use local time since MSDOS does. */
  return dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday,
                 s->tm_hour, s->tm_min, s->tm_sec);
}
utime
       #include < sys/types.h >
       #include < utime.h >

       int utime(const char *filename, const struct utimbuf *times);

예제 참고
http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/utime

#include < sys/types.h >
#include < utime.h >
#include < sys/time.h >
#include < stdio.h >
#include < string.h >

int main()
{
    struct utimbuf ubuf;
    ubuf.actime = time((time_t *)0);
    ubuf.modtime = time((time_t *)0);

    // 접근,수정 시간을 현재 시간으로 변경한다.
    utime("sizeof.c", NULL);

    // NULL 대신 actime,modtime 을 세팅해서 
    // 직접 값을 지정해줄수도 있다. 
    utime("sizeof.c", &ubuf);
    return 0;
}
해당 범위를 벗어나면 락을 해제하는 패턴.

예제 1 ) Scoped Locking 패턴을 사용하지 않은 예제
 변수 m 은 뮤텍스.

virtual int handle_data()
{
    while( log_record() != -1 )
    {
        if( m.acquire() == -1 ) return 0;
        ++request_count;    // 요청개수 증가
        m.release();        // 잠금해제
    }

    m.acquire();
    int cnt = request_count;
    m.release();
    cout << "request_count" = " << cnt << endl;
}

예제 2 ) Scoped Locking 패턴을 사용한 예제
 변수 m 은 뮤텍스.

virtual int handle_data()
{
    while( log_record() != -1 )
    {
        // 생성자에서 잠금 획득
        ACE_GUARD_RETURN ( ACE_Thread_Mutex, guard, m , -1 );
        ++request_count;    // 요청개수 증가
        // 소멸자에서 잠금 해제.
    }

    {
        // 생성자에서 잠금 획득
        ACE_GUARD_RETURN ( ACE_Thread_Mutex, guard, m , -1 );
        int cnt = request_count;
        // 소멸자에서 잠금 해제.
    }

    cout << "request_count" = " << cnt << endl;
}
아무것도 하지 않는 객체를 만드는것.

예제)

class ACE_Null_Mutex
{
public:
    ACE_Null_Mutex( const char * = 0, ACE_mutexattr_t * = 0 ) {}
    int acquire() { return 0; }
    int release() { return 0; }
    // ....
};

+ Recent posts