 d6c6e05727
			
		
	
	d6c6e05727
	
	
	
		
			
			Co-authored-by: zhjc1124 <zhjc1124@gmail.com> Co-authored-by: BinChenn <binchenn.bc@gmail.com> Co-authored-by: oceanoverflow <oceanoverflow@gmail.com>
		
			
				
	
	
		
			23 lines
		
	
	
		
			557 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			557 B
		
	
	
	
		
			C
		
	
	
	
	
	
| # define USSL_DEFAULT_VERSION 1
 | |
| 
 | |
| int send_negotiation_message(int fd, const char *b, int sz)
 | |
| {
 | |
|   int err = 0;
 | |
|   char buf[USSL_BUF_LEN];
 | |
|   negotiation_head_t *h = (typeof(h))buf;
 | |
|   if (sz + sizeof(*h) > sizeof(buf)) {
 | |
|     err = -EINVAL;
 | |
|   } else {
 | |
|     h->magic = NEGOTIATION_MAGIC;
 | |
|     h->version = USSL_DEFAULT_VERSION;
 | |
|     h->len = sz;
 | |
|     memcpy(h + 1, b, sz);
 | |
|     ssize_t wbytes = 0;
 | |
|     while ((wbytes = libc_write(fd, buf, sizeof(*h) + sz)) < 0 && EINTR == errno)
 | |
|       ;
 | |
|     if (wbytes != sz + sizeof(*h)) {
 | |
|       err = -EIO;
 | |
|     }
 | |
|   }
 | |
|   return err;
 | |
| } |