Changeset ad49c9d96804ded80d32f8bb271ad728841209ce

Show
Ignore:
Timestamp:
06/21/2010 03:32:04 PM (2 years ago)
Author:
Adrien Demarez <adrien.demarez@…>
Parents:
87b9442439e824bb10ace9cbb48d5a40bea6734b
git-committer:
Adrien Demarez <adrien.demarez@…> (06/21/2010 03:32:04 PM)
Message:

Fix crash because freeing the pcap context inside the pcap callback

Location:
src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • src/common_thp.cpp

    r33d17dc rad49c9d  
    4242    : dbus(dbus_engine), thp(NULL), 
    4343    last_getservices(0), 
    44     running(false) 
     44    running(false), 
     45    reconnect_thp(false) 
    4546{ 
    4647} 
     
    5455{ 
    5556    thp_engine_check_fd(thp, rfds, wfds); 
     57    if (reconnect_thp && reconnect() == ERROR_NO_ERROR) 
     58        reconnect_thp = false; 
    5659} 
    5760 
     
    8386} 
    8487 
    85 void wimax_thp::reconnect() 
     88int wimax_thp::reconnect() 
    8689{ 
    8790    wimax_debug("disconnecting\n"); 
     91    int sockfd = thp_engine_get_fd(thp); 
    8892    thp_engine_free(thp); 
    89     int sockfd = thp_engine_get_fd(thp); 
    9093    FD_CLR(sockfd, saved_rfds); 
    9194    sleep(3); 
    9295    running = false; 
    9396 
    94     if (connect(networkInterface.c_str(), saved_sockmax, saved_rfds) != ERROR_NO_ERROR) 
     97    if (connect(networkInterface.c_str(), saved_sockmax, saved_rfds) != ERROR_NO_ERROR) { 
    9598        wimax_warn("Could not reconnect to THP"); 
    96     else 
     99        return -ERROR_FAILURE; 
     100    } else { 
    97101        wimax_debug("Reconnected to THP\n"); 
     102        return ERROR_NO_ERROR; 
     103    } 
    98104} 
    99105 
  • src/common_thp.h

    r33d17dc rad49c9d  
    3535    void check_fd(fd_set *rfds, fd_set *wfds); 
    3636    int connect(const std::string &interface, int *sockmax, fd_set *rfds); 
    37     void reconnect(); 
     37    int reconnect(); 
    3838    virtual int handle(const char *name, uint8_t *ptr, size_t length); 
    3939    virtual int handle_ack(uint16_t ack_nb) { return ERROR_NO_ERROR; }; 
     
    4949    int handle_log(uint8_t *ptr, size_t length); 
    5050    int send(uint8_t *data, size_t length, uint16_t *seq_nb = NULL); 
    51  
    52 protected: 
    5351    wimax_ms_dbus *dbus; 
    5452    std::string networkInterface; 
     53    bool reconnect_thp; 
    5554 
    5655private: 
  • src/ms_thp.cpp

    rc373b92 rad49c9d  
    201201        status, error, rxbytes); 
    202202    if (state == BFH_STATE_START_APPLI) 
    203         reconnect(); 
     203        reconnect_thp = true; 
    204204    return ERROR_NO_ERROR; 
    205205} 
  • src/wimax/thp.c

    r4ec3361 rad49c9d  
    114114    engine->services[0].title = strdup("GetServices"); 
    115115    engine->services[0].id = 1; 
    116  
    117116    return engine; 
    118117} 
     
    126125    pcap_close(engine->pcap_handle); 
    127126    free(engine); 
     127    engine = NULL; 
    128128} 
    129129 
     
    337337    static int fragbuffer_index = 0; 
    338338 
     339    if (!engine || !ptr) 
     340        return -ERROR_FAILURE; 
     341 
    339342    if (length < sizeof(*transport)) 
    340343    {