Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

void SlowSocket::close(){} 这是直接给类添加类方法吗?

我在看一个代码的时候:

void SlowSocket::close() {
  if (-1 == sockfd_) return;

  slowlog(LOG_DEBUG, "closing slow socket %d
", sockfd_);
  if(ssl_) {
    SSL_free(ssl_);
    SSL_CTX_free(ssl_ctx_);
    ssl_ = NULL;
    ssl_ctx_ = NULL;
  }
  requests_to_send_ = 0;
  followups_to_send_ = 0;
  ::close(sockfd_);  // 这句话看不明白
  sockfd_ = -1;
}

有两个地方不理解:
1)void SlowSocket::close(){}

这是给类SlowSocket添加类方法close()吗?
2)方法中直接写:
::close(sockfd_);
这是什么意思呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

作用域,比如:

void close(int id) {
    printf("global close");
}
class Foo {
    void close() {
        ::close(1);
    }
}

找本书打打基础吧


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...