~brianaker/gearmand/warning-usage

« back to all changes in this revision

Viewing changes to libgearman/connection.cc

  • Committer: Brian Aker
  • Date: 2013-08-07 22:23:36 UTC
  • mto: This revision was merged to the branch mainline in revision 853.
  • Revision ID: brian@tangent.org-20130807222336-6gs9tjksajrolatc
Additional SSL cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
295
295
{
296
296
  if (_ssl)
297
297
  {
298
 
#if defined(HAVE_CYASSL) && HAVE_CYASSL
299
 
    CyaSSL_shutdown(_ssl);
300
 
    CyaSSL_free(_ssl);
 
298
#if defined(HAVE_SSL) && HAVE_SSL
 
299
    SSL_shutdown(_ssl);
 
300
    SSL_free(_ssl);
301
301
    _ssl= NULL;
302
302
#endif
303
303
  }
678
678
 
679
679
gearman_return_t gearman_connection_st::enable_ssl()
680
680
{
681
 
#if defined(HAVE_CYASSL) && HAVE_CYASSL
 
681
#if defined(HAVE_SSL) && HAVE_SSL
682
682
  if (universal.ssl())
683
683
  {
684
 
    _ssl= CyaSSL_new(universal.ctx_ssl());
 
684
    _ssl= SSL_new(universal.ctx_ssl());
685
685
    if (_ssl == NULL)
686
686
    {
687
687
      close_socket();
688
688
      return gearman_error(universal, GEARMAN_COULD_NOT_CONNECT, "CyaSSL_new() failed to return a valid object");
689
689
    }
690
690
 
691
 
    if (CyaSSL_set_fd(_ssl, fd) != SSL_SUCCESS)
 
691
    if (SSL_set_fd(_ssl, fd) != SSL_SUCCESS)
692
692
    {
693
693
      close_socket();
694
 
      char errorString[80];
695
 
      return gearman_error(universal, GEARMAN_COULD_NOT_CONNECT, CyaSSL_ERR_error_string(CyaSSL_get_error(_ssl, 0), errorString));
 
694
      char errorString[SSL_ERROR_SIZE];
 
695
      ERR_error_string_n(SSL_get_error(_ssl, 0), errorString, sizeof(errorString));
 
696
      return gearman_error(universal, GEARMAN_COULD_NOT_CONNECT, errorString);
696
697
    }
697
698
  }
698
699
#endif
836
837
      while (send_buffer_size != 0)
837
838
      {
838
839
        ssize_t write_size;
839
 
#if defined(HAVE_CYASSL) && HAVE_CYASSL
 
840
#if defined(HAVE_SSL) && HAVE_SSL
840
841
        write_size= 0;
841
842
        if (_ssl)
842
843
        {
 
844
#if defined(HAVE_CYASSL) && HAVE_CYASSL
843
845
          write_size= CyaSSL_send(_ssl, send_buffer_ptr, int(send_buffer_size), MSG_NOSIGNAL);
 
846
#elif defined(HAVE_OPENSSL) && HAVE_OPENSSL
 
847
          write_size= SSL_write(_ssl, send_buffer_ptr, int(send_buffer_size));
 
848
#endif
844
849
          if (write_size <= 0)
845
850
          {
846
851
            int err;
847
 
            switch ((err= CyaSSL_get_error(_ssl, int(write_size))))
 
852
            switch ((err= SSL_get_error(_ssl, int(write_size))))
848
853
            {
849
854
              case SSL_ERROR_WANT_CONNECT:
850
855
              case SSL_ERROR_WANT_ACCEPT:
861
866
              default:
862
867
                {
863
868
                  char errorString[80];
864
 
                  CyaSSL_ERR_error_string(err, errorString);
 
869
                  ERR_error_string_n(err, errorString, sizeof(errorString));
865
870
                  close_socket();
866
871
                  return gearman_universal_set_error(universal, GEARMAN_LOST_CONNECTION, GEARMAN_AT, "SSL failure(%s)", errorString);
867
872
                }
869
874
          }
870
875
        }
871
876
        else
872
 
#endif
 
877
#endif // define(HAVE_SSL)
873
878
        {
874
879
          write_size= ::send(fd, send_buffer_ptr, send_buffer_size, MSG_NOSIGNAL);
875
880
        }
1128
1133
 
1129
1134
  while (1)
1130
1135
  {
1131
 
#if defined(HAVE_CYASSL) && HAVE_CYASSL
 
1136
#if defined(HAVE_SSL) && HAVE_SSL
1132
1137
    if (_ssl)
1133
1138
    {
 
1139
# if defined(HAVE_CYASSL) && HAVE_CYASSL
1134
1140
      read_size= CyaSSL_recv(_ssl, data, int(data_size), MSG_NOSIGNAL);
1135
 
      if (read_size <= 0)
 
1141
# elif defined(HAVE_OPENSSL) && HAVE_OPENSSL
 
1142
      read_size= SSL_read(_ssl, data, int(data_size));
 
1143
# endif
 
1144
      if (read_size == 0)
 
1145
      { } // Socket has been closed
 
1146
      else if (read_size < 0)
1136
1147
      {
1137
 
        int sendErr= CyaSSL_get_error(_ssl, int(read_size));
 
1148
        int sendErr= SSL_get_error(_ssl, int(read_size));
1138
1149
        if (sendErr != SSL_ERROR_WANT_READ)
1139
1150
        {
1140
1151
          char errorString[80];
1141
 
          int err= CyaSSL_get_error(_ssl, 0);
1142
 
          CyaSSL_ERR_error_string(err, errorString);
 
1152
          ERR_error_string_n(sendErr, errorString, sizeof(errorString));
1143
1153
          close_socket();
1144
1154
          ret= gearman_universal_set_error(universal, GEARMAN_LOST_CONNECTION, GEARMAN_AT,
1145
1155
                                           "SSL failure(%s)", errorString);
1148
1158
      }
1149
1159
    }
1150
1160
    else
1151
 
#endif
 
1161
#endif // defined(HAVE_SSL)
1152
1162
    {
1153
1163
      read_size= ::recv(fd, data, data_size, MSG_NOSIGNAL);
1154
1164
    }