×
Namespaces

Variants
Actions
Revision as of 08:41, 15 December 2011 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Open C 套接字: shutdown 方法

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
dougcn 在 24 Jun 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

Open C 套接字: shutdown 方法

shutdown关闭一部分全双工连接。

int shutdown (int sockfd, int how);

shutdown系统调用引起与待关闭的文件描述符sockfg关联的套接字全双工连接的全部或部分关闭。how参数指定shutdown的类型。

可能值有:

  • SHUT_RD -- 禁止后续接受
  • SHUT_WR -- 禁止后续发送
  • SHUT_RDWR-- 禁止后续接受与发送

下面是Open C套接字接口的shutdown函数的用法:

#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
TInt shutdown_example()
{
int sock_fd;
sockaddr_in addr,ss;
unsigned int len;
 
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(5000);
bind(sock_fd,(sockaddr*)&addr,sizeof(addr));
shutdown(sock_fd, SHUT_RD)
close(sock_fd);
}

内部链接

Internal Links

This page was last modified on 15 December 2011, at 08:41.
141 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×