Changeset 2745


Ignore:
Timestamp:
Feb 19, 2011, 5:04:18 PM (11 years ago)
Author:
schwittmann
Message:

External Client: added support for clean shutdowns

Location:
trunk/CrypPlugins/KeySearcher/ExternalClient
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Main.cpp

    r2493 r2745  
    99#include <netinet/in.h>
    1010#include <arpa/inet.h>
     11#include <signal.h>
    1112
    1213#include "Network.h"
     
    3738}
    3839
     40bool receivedSigInt = false;
     41
     42void terminate(int parm)
     43{
     44    if(receivedSigInt)
     45    {
     46        printf("Force quitting...\n");
     47        exit(1);
     48    }
     49    printf("Received SIGINT, will exit after current chunk\n");
     50    printf("Press again to force quit.\n");
     51    receivedSigInt = true;
     52}
     53
    3954int main (int argc, char **argv)
    4055{
     
    6277    }
    6378
     79    // CTRL+C
     80    signal (SIGINT, terminate);
     81
    6482    sockaddr_in serv_addr;
    6583    bzero((char *) &serv_addr, sizeof(serv_addr));
     
    6886    Cryptool cryptool;
    6987
    70     while(true)
     88    while(!receivedSigInt)
    7189    {
    7290        if(!lookup(argv[1], serv_addr))
     
    7593            continue;
    7694        }
    77         networkThread(serv_addr, port, password, &cryptool);
     95        networkThread(serv_addr, port, password, &cryptool, &receivedSigInt);
    7896        printf("Reconnecting in %u seconds\n", RECONNECT_TIME);
    7997        sleep(RECONNECT_TIME);
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Network.cpp

    r2716 r2745  
    6262// Queue of completed jobs
    6363std::queue<JobResult> finishedJobs;
    64 void GetJobsAndPostResults(PlatformIndependentWrapper& wrapper, const char* password, Cryptool* cryptool)
     64void GetJobsAndPostResults(PlatformIndependentWrapper& wrapper, const char* password, Cryptool* cryptool, bool* receivedSigInt)
    6565{
    6666    wrapper.WriteInt(ClientOpcodes::HELLO);
     
    7575    }
    7676    // loop will be escaped by wrapper exceptions
    77     while(true)
     77    while(!*receivedSigInt)
    7878    {
    79         // TODO: soft break
    8079        printf("Requesting new job...\n");
    8180        wrapper.WriteInt(ClientOpcodes::JOB_REQUEST);
     
    114113}
    115114
    116 void networkThread(sockaddr_in serv_addr, int port, const char* password, Cryptool* cryptool)
     115void networkThread(sockaddr_in serv_addr, int port, const char* password, Cryptool* cryptool, bool* receivedSigInt)
    117116{
    118117    printf("Connecting to %s on port %i\n", inet_ntoa(serv_addr.sin_addr), port);
     
    141140    try{
    142141        PlatformIndependentWrapper w(sockfd);
    143         GetJobsAndPostResults(w, password, cryptool);
     142        GetJobsAndPostResults(w, password, cryptool, receivedSigInt);
    144143    } catch(SocketException)
    145144    {
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Network.h

    r2493 r2745  
    33#include "Cryptool.h"
    44
    5 void networkThread(sockaddr_in, int, const char*, Cryptool* cryptool);
     5void networkThread(sockaddr_in, int, const char*, Cryptool* cryptool, bool*);
    66
Note: See TracChangeset for help on using the changeset viewer.